Skip to content

Reading an R plotly object saved as RDS across different systems #1376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ndrubins opened this issue Oct 24, 2018 · 5 comments · Fixed by #1384
Closed

Reading an R plotly object saved as RDS across different systems #1376

ndrubins opened this issue Oct 24, 2018 · 5 comments · Fixed by #1384

Comments

@ndrubins
Copy link

I'm generating plotly figures in R on my institution's computing cluster and I'd like to be able to view them on my personal mac (e.g., saving a PDF or SVG static image doesn't work well on the cluster - too many installations involved to get plotly::orca to work).

I thought that saving the plotly object to an RDS format file, e.g.:

library(plotly)
p <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length,
        marker = list(size = 10,
                       color = 'rgba(255, 182, 193, .9)',
                       line = list(color = 'rgba(152, 0, 0, .8)',
                                   width = 2))) %>%
  layout(title = 'Styled Scatter',
         yaxis = list(zeroline = FALSE),
         xaxis = list(zeroline = FALSE))
saveRDS(r,"p.RDS")

And then reading it in RStudio on my mac shouldn't be a problem. However, when trying to run:

readRDS("p.RDS")

on my mac's RStudio, I get this error:

Error in dirname(to) : a character vector argument expected

Reading it into a variable:
p <- readRDS("p.RDS")
does not cause an error so the object is read in successfully but cannot be displayed.

I see that p$dependencies shows the path to where plotly/htmlwidgets/lib/typedarray is installed on the cluster. Could that be the issue? If so is there anyway to avoid that or change it?

Alternatively, is it possible to simply recreate a plotly figure from p$x?

@cpsievert
Copy link
Collaborator

I see that p$dependencies shows the path to where plotly/htmlwidgets/lib/typedarray is installed on the cluster. Could that be the issue? If so is there anyway to avoid that or change it?

Yes, assuming you need to save the R object, there isn't a great workaround other than to manually override the local file path attached to each dependency. If you can get away with just saving the HTML/JS/CSS result, use htmlwidgets::saveWidget() or htmltools::save_html().

@cpsievert cpsievert reopened this Oct 31, 2018
@cpsievert
Copy link
Collaborator

Actually, reopening since I think it might be possible to use relative versus absolute paths

cpsievert added a commit to cpsievert/crosstalk that referenced this issue Oct 31, 2018
cpsievert added a commit to cpsievert/crosstalk that referenced this issue Oct 31, 2018
cpsievert added a commit to cpsievert/crosstalk that referenced this issue Dec 10, 2018
@ndrubins
Copy link
Author

Hi,

Sorry to be a nudge on this.

I installed the latest plotly from github (plotly_4.8.0.9000) and tried the example above again.

I don't get the Error in dirname(to) : a character vector argument expected now, but the plot is not loading on the viewer pane.

Although the first p$dependencies list element now shows a relative path:
..$ file: chr "htmlwidgets/lib/typedarray"
The second and third p$dependencies list elements still show the absolute paths of R/crosstalk/lib/jquery and R/crosstalk/www, respectively, to my R installation on the cluster.

Is this the reason why I'm still not able to load the figure on my Mac?
And if so, can this be fixed?

Thanks a lot

@cpsievert
Copy link
Collaborator

You'll also need the development version of crosstalk: devtools::install_github("rstudio/crosstalk")

@ndrubins
Copy link
Author

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants