Skip to content

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

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
wants to merge 5 commits into from
Closed

Conversation

cpsievert
Copy link
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
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
Copy link
Collaborator Author

cpsievert commented Jan 20, 2016

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

@timelyportfolio
Copy link
Collaborator

timelyportfolio commented May 19, 2016

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
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
Copy link
Collaborator

timelyportfolio commented May 19, 2016

@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
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
Copy link
Collaborator

timelyportfolio commented May 19, 2016

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

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

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
Copy link
Collaborator Author

cpsievert commented Dec 6, 2017

@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
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