Reputation: 171
I'm looking for a way to render my plotly plot directly to a browser instead of RStudio 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?
Upvotes: 9
Views: 6601
Reputation: 171
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.
Upvotes: 7
Reputation: 938
An example from this site might help:
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.
Upvotes: 0