JuliaPlots / PlotlyJS.jl

Julia library for plotting with plotly.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PlotlyJS.PlotlyBase.to_html() does not export a stand alone HTML

StefanPofahl opened this issue · comments

Describe the bug
A clear and concise description of what the bug is.

I can not export a stand-alone / off-line-ready html-figure.
It is not clear, how to use the parameter include_plotlyjs correctly.
See also:
#366

Version info

Please provide the following:

  1. output of julia command versioninfo()
Julia Version 1.6.7
Commit 3b76b25b64 (2022-07-19 15:11 UTC)        
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
  WORD_SIZE: 64    
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_SSL_CA_ROOTS_PATH = 
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 
  1. Output running the following in Julia 0.7 or greater: using Pkg; pkg"status" (if you are on Julia 0.6 or earlier run Pkg.status())
      Status `C:\Users\stefanpofahl\.julia\environments\v1.6\Project.toml`
  [093aae92] BSplineKit v0.11.3
  [336ed68f] CSV v0.10.9
  [7c7805af] Clapeyron v0.4.0
  [8f4d0f93] Conda v1.7.0
  [992eb4ea] CondaPkg v0.2.15
  [e084ae63] CoolProp v0.1.0
  [717857b8] DSP v0.7.8
  [39dd38d3] Dierckx v0.5.2
  [aac5d7a0] EquivalentCircuits v0.2.1 `https://github.com/MaximeVH/EquivalentCircuits.jl.git#master`
  [7a1cc6ca] FFTW v1.5.0
  [5789e2e9] FileIO v1.16.0
  [a98d9a8b] Interpolations v0.14.7
  [033835bb] JLD2 v0.4.29
  [682c06a0] JSON v0.21.3
  [b964fa9f] LaTeXStrings v1.3.0
  [2b0e0bc5] LanguageServer v4.3.1
  [5ad8b20f] PhysicalConstants v0.2.3
  [a03496cd] PlotlyBase v0.8.19
  [f0f68f2c] PlotlyJS v0.18.10
  [438e738f] PyCall v1.95.0
  [6099a3de] PythonCall v0.9.10
  [274fc56d] PythonPlot v1.0.0
  [295af30f] Revise v3.5.0
  [d6ea1423] RobustModels v0.4.5
  [cf896787] SymbolServer v7.2.1
  [1986cc42] Unitful v1.12.2
  [fdbf4ff8] XLSX v0.8.4
  [de0858da] Printf

In case you're still looking for a way to export a stand-alone HTML file, this is what I use:

julia> using PlotlyJS

julia> savefig(Plot([scatter(x=1:10, y=randn(10))], Layout(hovermode="closest")), "/data/p.html"); run(`sed -i /data/p.html -e '/mathjax/d'`); run(`sed -i /data/p.html -e 's|https://cdn.plot.ly|.|'`);

The sed commands aren't needed, but I use them so that HTML file doesn't require any network requests and loads a local copy of the javascript library.

Thanks a lot, I will try :-)

commented

I am also looking for standalone export.
It's nearly possible with PlotlyBase.to_html.
By setting the kwarg include_plotlyjs="directory", the html script tag is changed to <script src="plotly.min.js"></script> (same for mathjax kwarg). We only have to provide the javascript file ourselves.
It would be convenient to have an option include_plotlyjs="download" to download and interpolate the javascript into the HTML file for offline standalone usage.