r - 在 Firefox 中打开 plotly 离线网页

标签 r plotly

我意识到这不完全是一个编程问题。我正在运行以下代码,然后将绘图导出为网页(在 Windows 10 上使用 R Studio 1.0.44R 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")

最佳答案

有一个相关问题:Why are plotly-rendered graphs not working on Mozilla

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

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

---
title: "Your title"
output:
  html_document:
    self_contained: false
---

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

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

关于r - 在 Firefox 中打开 plotly 离线网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41819685/

相关文章:

r - 按 id 从宽到长收集列

javascript - Python点击事件的Plotly(离线)

r - 省略某些值时如何创建桑基图

r - 如何将文本添加到 r 中的绘图箱线图中

将曲面图中的线条删除到 x、y 和 z 平面

r - R 图中条的边缘宽度

r - 在 R 中,如何使用 quote 或 bquote 引用注释?

r - 如何针对 3 个组更改列的值

python - 如何在Python中排序堆积条形图?

r - "Globe"形状的俄罗斯 map