Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening plotly offline webpage in Firefox

Tags:

r

plotly

I realize this is not exactly a programming question. I am running the following code and then exporting the plot as a web-page (using R Studio 1.0.44 & R 3.3.1 on Windows 10). When I try to open the saved web-page in Firefox 50.1.0, I don't see anything. The web-page opens fine in Chrome. I have had the problem in two different computers. Could you please check if this is a reproducible problem. If you can think of something I may be doing wrong, please let me know.

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")
like image 829
d.b Avatar asked Jan 24 '17 03:01

d.b


1 Answers

There is a related question at: Why are plotly-rendered graphs not working on Mozilla

It is worth mentioning that this problem does not occur only with offline webpages. If you upload your .html file to a gh-pages branch on GitHub for example, you'll also have problems loading the page with Mozilla.

The short answer (so far) is that you have to do the following workaround in order to get things working in Firefox. Add self_contained: false to the YAML header:

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

The credit for this solution goes to cpsievert (https://github.com/ropensci/plotly/issues/721)

Note: When you add self_contained: false you no longer have a standalone HTML file as output (https://rmarkdown.rstudio.com/html_document_format.html - Document Dependencies).

like image 200
allanvc Avatar answered Nov 04 '22 13:11

allanvc