【问题标题】:Opening plotly offline webpage in Firefox在 Firefox 中打开 plotly 离线网页
【发布时间】:2017-01-24 03:48:05
【问题描述】:

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

【问题讨论】:

  • 在 macOS 上对我来说(加上 Safari 和 Opera)看起来都很好。不过,可能是堆栈某些部分的版本中的错误,因此修复起来并不容易。
  • 你可以用 F12 打开开发者控制台。控制台输出是否有错误?
  • 我无法在 linux、firefox 50.1.0 上重现此错误。您是否安装了可能会发生冲突的附加组件或插件?尝试禁用它们。你有阻止 javascript (about:config javascript.enabled)
  • 在我的笔记本上(内存比我的台式机少得多)我遇到了这个问题——Firefox 消耗了大量内存(超过 2G)并且几乎崩溃了。在第二个选项卡中打开 html 文件后,我没有任何输出,并且出现有关开发控制台内存不足的消息……这似乎是一个已知但当前未修复的问题 - 请参阅 stackoverflow.com/questions/41601669/…
  • 我在这里发表了评论以获取更多参考github.com/ropensci/plotly/issues/721

标签: r plotly


【解决方案1】:

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

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

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

---
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 - 文档依赖项)。

【讨论】:

    【解决方案2】:

    供python使用

    url = plotly.offline.plot(data,filename='Changes.html',auto_open=False)

    subprocess.call([r'C:\Program Files\Mozilla Firefox\firefox.exe','-new-tab', url])

    【讨论】:

      猜你喜欢
      • 2019-06-21
      • 2017-08-02
      • 2017-12-12
      • 2017-04-27
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      • 2014-06-29
      • 1970-01-01
      相关资源
      最近更新 更多