I am trying to create some 3D plots using plotly package.
The code that I am using is their tutorial example
library(plotly)
# volcano is a numeric matrix that ships with R
fig <- plot_ly(z = ~volcano)
fig <- fig %>% add_surface()
fig
However, I get the following output. I already followed the guideline in https://www.thewindowsclub.com/webgl-is-not-supported-on-chrome-firefox but still did not work. Any idea why?
I solved it forcing RStudio to use 'Desktop OpenGL'. In RStudio, I went to [Tools/Global Options.../Advanced] and choosing 'Desktop OpenGL' in Rendering engine.
Source:
community.rstudio.com: WebGL is not supported by your browser - Plotly
Related Plotly GitHub Issue 3573
Related
Unfortunately, I struggle to show a reproducible example here. The issue occurs only, when I add a locally saved raster file (140mb) to a leaflet map. And I don't know how to share such a large file here. The map shows fine in the rStudio viewer and in Chrome. But it fails to show the raster in Firefox and Safari (Firefox on OSX and iOS). Even auto zoom and pan does not work.
When I add a system raster file, everything works as expected:
library(leaflet)
library(leafem)
library(raster)
library(stars) #to access the stars system.file
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x2 <- raster(tif)
map_raster <- leaflet() %>%
addTiles() %>%
leafem:::addGeoRaster(
x2,
opacity = 1,
colorOptions = colorOptions(
palette = grey.colors(256)
)
)
library(htmlwidgets)
saveWidget(map_raster, file = "TestExport_raster.html", selfcontained = T)
But when I replace x2 with the local raster, it does not work. Tried adding an object from the raster and the stars package, but with no difference.
Any help on that? Is the raster just too big for a leaflet-map?
The question might be related to this one:
saving R leaflet map as html: tiles not included
Best,
Beni
Im trying to use the plotly library on google colab using R, i created a new colaboratory notebook with R kernel , tried this simple code from plotly's documentation and result is white cell (seems size of histogram but its not rendering) anyone did experience this issue?
p <- plot_ly(x = ~rnorm(50), type = "histogram")
p
I try to find a way to save a plotly graph as png without installing orca (I'm not allowed to).
It appears that if I plot my graphics, lets say :
library(dplyr)
library(plotly)
p <- plot_ly(z = ~volcano) %>% add_surface()
p
and then clic on export>save as image>Save as png, the resulting static plot is available on my computer
But If I try to use classical png() like this :
png("myvolcano.png")
plot_ly(z = ~volcano) %>% add_surface()
dev.off()
I get a blank png...
(while it's working for a classical plot(1) )
How to reproduce by code what I get from the menu bar ?
Thank you!
Hi this is more a comment than an answer but my reputation does not allow me to comment.
You can use 2 strategies to export plotly graphs:
use orca() function in the plotly pkg (if you ?orca will find all the explanations)
use htmlwidgets::saveWidget(p, file = "myvolcano.html") which downloads in html format
In the past there was a function export() but it is deprecated now.
Hope this helps.
I was trying to create a Plotly map in R using plot_geo. I wasn't getting any errors, but the Viewer was returning a blank map. The Plotly mode bar was showing up, but everything else was blank.
I couldn't even get the code below from the plot_geo help page to work:
library(plotly)
library(dplyr)
map_data("world", "canada") %>%
group_by(group) %>%
plot_geo(x = ~long, y = ~lat) %>%
add_markers(size = I(1))
Has anyone else ran into this problem? I haven't had any trouble with plotly in R in the past.
I used your code but I had to load the following packages first:
library(dplyr)
library(ggplot2)
library(plotly)
The map generates correctly on my device, i.e. the borders of Canada are highlighted. The remaining countries don't have borders:
I'm using the plotly version 4.5.6.9000.
If you are still running into your problems, try updating packages used. Restarting your R session could also help.
I'm looking for a way to render my plot_ly plot directly to a browser in stead of r-studios default viewer. I've searched the plotly documentation but I only see a reference to the default behavior of opening the plot to a browser when running r from a terminal.
Does anyone know how to open to a browser window by default? Maybe a parameter to the plotly layout() option?
Alright I found a simple solution in the related questions section next to my original question. Sorry I didn't find it before. stackoverflow.com/questions/36868743 .
Setting: options(viewer=NULL) in the script disables the viewer and opens my plot in the browser.
Not really elegant and how to turn the default viewer back on is still a little mystery.
An example from this site might help:
http://www.statsblogs.com/2014/02/06/protected-online-r-and-plotly-graphs-canadian-and-u-s-maps-old-faithful-with-multiple-axes-overlaid-histograms/
library(plotly)
p <- plotly(username="MattSundquist", key="4om2jxmhmn")
library(maps)
data(canada.cities)
trace1 <- list(x=map(regions="canada")$x,
y=map(regions="canada")$y)
trace2 <- list(x= canada.cities$long,
y=canada.cities$lat,
text=canada.cities$name,
type="scatter",
mode="markers",
marker=list(
"size"=sqrt(canada.cities$pop/max(canada.cities$pop))*100,
"opacity"=0.5)
)
response <- p$plotly(trace1,trace2)
url <- response$url
filename <- response$filename
browseURL(response$url)
The main take home being browseURL(response$url). Notice the sign in as well.