Skip to content

Copy extras over from plotly.js, if necessary - #411

Closed
cpsievert wants to merge 5 commits into
masterfrom
fix/assets
Closed

cpsievert wants to merge 5 commits into
masterfrom
fix/assets

Conversation

@cpsievert

Copy link
Copy Markdown
Collaborator

This addresses #375 and #356 by leveraging a new environment variable which should point to the plotly.js source. In other words, you can render MathJax and/or maps without an internet connection by doing something like:

git clone https://github.com/plotly/plotly.js.git
cd plotly.js
export plotly_jsdir=`pwd`
echo "Sys.setenv('plotly_jsdir', '$plotly_jsdir')" >> ~/.Rprofile

@cpsievert

Copy link
Copy Markdown
Collaborator Author

TODO: why does this warning occur?

> plot_ly()
Warning message:
In file(con, "r") :
  file("") only supports open = "w+" and open = "w+b": using the former

@cpsievert

cpsievert commented Jan 20, 2016 •

Copy link
Copy Markdown
Collaborator Author

Also, injecting <script> to load mathjax via CDN isn't working(╯°□°)╯ ┻━┻

@timelyportfolio

timelyportfolio commented May 19, 2016 •

Copy link
Copy Markdown
Collaborator

I am not sure of precedent here with other packages, so I will look for other examples of similar functionality. There is this script in rmarkdown to prune MathJax to a smaller size. Here are a couple of poorly named functions to download the additional assets from Plotly for maps and MathJax to start the discussion/iteration. Then we will need some add dependency functions to add the assets to the Plotly htmlwidget. We have the option to do either local or web assets in these added dependencies.

plotly_download_map_dep <- function(){
  # find location of htmlwidgets assets in plotly package
  plotly_dir <- system.file("htmlwidgets/lib",package="plotly")

  # check to see if directory already exists
  exists_map_dir <- 'plotlymaps' %in% basename(plotly_dir)

  maps_dir <- file.path(plotly_dir,"plotlymaps")

  if(!exists_map_dir){
    dir.create(maps_dir)
  }
  download.file(
    url = "https://cdn.rawgit.com/plotly/plotly.js/master/dist/plotly-geo-assets.js",
    destfile = file.path(maps_dir,"plotly-geo-assets.js")
  )
  return(file.path(maps_dir,"plotly-geo-assets.js"))
}

Here is how rmarkdown handles MathJax.

@cpsievert

Copy link
Copy Markdown
Collaborator Author

Thanks @timelyportfolio. I think I'd prefer to grab assets from the relevant plotly.js release via GitHub's API, sort of like the inst/plotlyjs.R script

@timelyportfolio

timelyportfolio commented May 19, 2016 •

Copy link
Copy Markdown
Collaborator

@cpsievert, can you explain why? This would require downloading the whole repo for a couple of files. I am looking now to see what is included in the release zip file. It is 24mb compressed. Note, this function pulls directly from the plotly.js github repo.

@cpsievert

Copy link
Copy Markdown
Collaborator Author

True, I'm mainly concerned about versioning of the assets. As @chriddyp mentions here, maybe we could grab the assets from our CDN (and hopefully those are versioned)?

@timelyportfolio

timelyportfolio commented May 19, 2016 •

Copy link
Copy Markdown
Collaborator

I was looking for the cdn location. Thanks for the pointer. Probably better to use that. I just found this line that along with this line sets the path to topos assets.

@fabiangehring

Copy link
Copy Markdown

I didn't follow the discussion in the different issues about making geo plots available...

But if size is an issue, why not offering the offline content in another package like "plotlyOffline", comparable to "shinythemes" and "shiny". Plotly could then stay the same and gaining an "asset"-config with values "auto", "offline" or "online". Auto could check if the required assets are available and use them if yes and download otherwise. Different asset versions could be managed like normal package version dependencies.

I think this would keep plotly small but available "offline" if necessary. And As far as I can tell the implementation shouldn't be too difficult?

@danielsjf

Copy link
Copy Markdown

What is the current status of this development? I like the idea of @fabiangehring as this practice is indeed used for many other R packages. The usage of online VS offline could be handled with an argument in the function or an option.

Specifically for the use case of #302, it is annoying that the maps are not shown in Rstudio. This has been an issue since late 2015.

@cpsievert

cpsievert commented Dec 6, 2017 •

Copy link
Copy Markdown
Collaborator Author

@danielsjf at this point, I would like have to rethink this PR and probably create a helper package, say plotlyDependencies, which would bundle and automatically infer which (minimal amount) of plotly assets are needed for rendering.

Unfortunately, at the moment, we don't fund have the time/funding. Please get in touch if you're interesting in helping out

@cpsievert

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #1283

@cpsievert cpsievert closed this Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants