html - Plotly legend get trimmed off in the R Markdown Html template with tabset
问题描述
I am trying to using tabset and iframe together in R markdown template
Here is the code
---
title: "A"
output:
html_document:
self_contained: false
lib_dir: libs
---
```{r}
library(plotly)
p <- plot_ly(mtcars, x = ~cyl, y = ~mpg, split = ~cyl, type = "violin", showlegend = TRUE)
htmlwidgets::saveWidget(p, file = "p.html", selfcontained = F)
```
## {.tabset .tabset-fade}
### X {.tabset .tabset-fade}
#### Q
```{r, echo=FALSE}
htmltools::tags$iframe(
src = "./p.html",
frameBorder = "0",
width = "80%",
height = "500"
)
```
#### W
```{r, echo=FALSE}
htmltools::tags$iframe(
src = "./p.html",
frameBorder = "0",
width = "80%",
height = "500"
)
```
The plotly widget in the first tab always look ok (Tab X, sub-tab Q)
However, the legend of the second tab always get cut off. (Tab X, sub-tab W)
These only happen in MacOS/Chrome but looks normal in MacOS/Safari.
Any idea of why these might happen?
Update
I think it has something to do with div’s display:none
.
Similar issue.
Possible solution? But no idea how to implement in R markdown.
Update possible solution
Try adding this to the beginning of R markdown. I think it works now!
```{css, echo=FALSE}
.tab-content>.tab-pane {
display: block;
height: 0px;
overflow: hidden;
padding: 0px
}
.tab-content>.active {
display: block;
height: auto;
padding: 12px
}
```
Thanks to the discussion Here.
解决方案
推荐阅读
- sed - gnu sed 在模式匹配后删除部分行与特殊字符
- java - 文件可用后立即运行 Spring Batch Job
- c++ - 检查 boost::interprocess::shared_memory_object 是否为空?
- python-3.x - 初始化不同大小的数组的numpy数组
- python - Python:为 Python 2 和 Python 3 安装 VirtualEnv
- python - 使用python的离散对数
- macros - 为什么动态调用会导致“未定义函数”?
- node.js - 防止服务器在与 db 交互时崩溃
- paraview - 在小屏幕上查看“字母过滤器”
- asp.net-mvc - 登录和注册链接从 mvc5 应用程序菜单栏中消失