user1549537
user1549537

Reputation: 171

Opening a plotly plot in a browser instead of a viewer in RStudio

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

Answers (2)

user1549537
user1549537

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

ljc
ljc

Reputation: 938

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.

Upvotes: 0

Related Questions