在Firefox中打开情节离线网页

d.b*_*d.b 8 r plotly

我意识到这不是一个编程问题.我正在运行以下代码,然后将绘图导出为网页(在Windows 10上使用R Studio 1.0.44&R 3.3.1).当我尝试打开保存的网页时Firefox 50.1.0,我什么都没看到.网页在Chrome中打开正常.我在两台不同的电脑上遇到了这个问题.你能否检查这是否是一个可重现的问题.如果你能想到我可能做错了什么,请告诉我.

set.seed(42)
mydata = data.frame(A = rnorm(20), B = rnorm(20), Index = sample(190:400,20)) 
require(plotly)
x = list(title = "A")
y = list(title = "B")     
mydata$interval = cut(mydata$Index,breaks = 20)   
plot_ly(mydata, x = ~A, y = ~B, type = "scatter",
        mode = 'markers', hoverinfo = 'text', colors = colorRampPalette(c("red", "black"),
        space = "rgb")(20),
        color = ~Index, text = ~paste(interval), marker = list(size=14)) %>%
        layout(xaxis = x, yaxis = y) %>%
        colorbar(title = "My Legend")
Run Code Online (Sandbox Code Playgroud)

all*_*nvc 3

有一个相关的问题:Why areplotly-rendered graphs not work on Mozilla

值得一提的是,这个问题不仅仅出现在离线网页上。例如,如果您将 .html 文件上传到 GitHub 上的 gh-pages 分支,则在使用 Mozilla 加载页面时也会遇到问题。

简短的回答(到目前为止)是,您必须执行以下解决方法才能在 Firefox 中正常运行。添加self_contained: false到 YAML 标头:

---
title: "Your title"
output:
  html_document:
    self_contained: false
---
Run Code Online (Sandbox Code Playgroud)

该解决方案的功劳归功于cpsievert ( https://github.com/ropensci/plotly/issues/721 )

注意:添加后,self_contained: false您不再有独立的 HTML 文件作为输出(https://rmarkdown.rstudio.com/html_document_format.html - 文档依赖项)。