【问题标题】:Is there a way to get plotly graphics to render when an html file generated with flexdashboard is opened locally?当使用 flexdashboard 生成的 html 文件在本地打开时,有没有办法让图形渲染?
【发布时间】:2020-05-10 22:57:20
【问题描述】:

一段时间以来,我一直在使用 flexdashboard 和 plotly graphics 制作 html 文件,直到最近才注意到,当我从本地驱动器打开文件时,我的仪表板中的选项卡没有呈现 plotly 图形。

考虑这个基本的 .rmd 文件:

---
title: "Test Dashboard"

output:
  html_document: flexdashboard::flex_dashboard
  pdf_document: default

---
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(arules)
library(plotly)
library(dplyr)
library(DT)
library(reshape2)
library(stringr)
library(crosstalk)

rf<-data.frame(happiness=c(1,2,3,4,5,6,7,8),
           laziness=c(3,4,6,1,2,5,6,1))






```


Association Rules
==================================
Column {.tabset}
----------------------------------

### Table


```{r what2, echo=FALSE, collapse=TRUE, message=FALSE,warning=FALSE}
datatable(rf, filter = 'top', extensions = 'Buttons', options = list(dom = 'Bfrtip', buttons = 
c('csv', 'excel','copy', I('colvis')),pageLength = 20, autoWidth = TRUE),rownames = FALSE)
```




### Plot

```{r what, echo=FALSE, collapse=TRUE, message=FALSE, warning=FALSE}


P<-plot_ly(rf,
       x=~happiness,
       y=~laziness, 
        color = ~happiness)
P
```

在上面的代码中,我包含了我经常加载的包,如果有人知道这些包之一是罪魁祸首。

当我在 Rstudio 中编织这个 .rmd 以在我的硬盘驱动器上生成一个 .html 文件时,该文件会按预期保存。

导航到文件并打开它(Chrome 和 firefox 已经过测试)导致用户可以很好地看到表格,但绘图的选项卡是空白的。

我当前实际查看绘图的解决方法是将“#plot”附加到浏览器中文件路径的末尾并点击刷新。当我这样做时,情节就出现了,一切都很好。

虽然这对我有用,但它确实降低了其他人使用我的输出文件的乐趣。

任何帮助将不胜感激。

【问题讨论】:

    标签: r knitr r-plotly flexdashboard


    【解决方案1】:

    似乎 plotly 无法获取默认宽度和高度,因此使用 NULL。在 plot_ly 调用中手动设置这些会使情节出现,例如:

    P<-plot_ly(rf,
           x=~happiness,
           y=~laziness, 
            color = ~happiness,
           width = 600, 
           height = 400)
    

    【讨论】:

      【解决方案2】:

      flexdashboard 中的函数 renderPlotly() 动态调整绘图图的大小。我在 Flexdahboard 上的一篇博文中使用过,请参阅:https://medium.com/analytics-vidhya/shiny-dashboards-with-flexdashboard-e66aaafac1f2

      【讨论】:

        猜你喜欢
        • 2020-08-13
        • 2019-10-15
        • 1970-01-01
        • 2019-12-21
        • 1970-01-01
        • 2020-03-24
        • 2020-11-17
        • 1970-01-01
        • 2021-03-01
        相关资源
        最近更新 更多