JunoLab / Weave.jl

Scientific reports/literate programming for Julia
http://weavejl.mpastell.com
MIT License
831 stars 95 forks source link

interactive plots in HTML output - how? #235

Closed josephmarturano closed 5 years ago

josephmarturano commented 5 years ago

First, thank you for this great package. It has already helped me communicate my results using Julia. I have no doubt this package is improving scientific communication around the world.

In my view, what would really bring Weave reports to the next level are embedded interactive plots. Such a report is beyond a traditional document editor with static plots (e.g., MS Word). I have been trying to embed interactive plots within a Weave HTML report, and read issues #47 and #186. But so far I have been unsuccessful. I tried searching online but have not found examples or instructions for how to generate an interactive HTML output, so I thought to open this issue and ask for help.

I am using a Windows 7 machine and VS Code with the Julia extension (v.0.12.0). Here are my attempts:

Attempt 1 In the editor, I entered and ran the following:

using Plots
plotly()
plot(randn(100))

I save the file as "test_interactive_weave.jl". Then in the VS Code Julia console, I entered the following Weave command:

using Weave; weave("C:/Julia/test_interactive_weave.jl", out_path=:doc, doctype="md2html")

But in the rendered HTML file, I see the code but instead of a plot, I see red text that reads:

ERROR: only png or svg allowed. got: :html

Attempt 2 Next, I tried changing "plotly()" to "plotlyjs()", but after entering the same Weave command, in the rendered HTML output I see the following red text:

ERROR: UndefVarError: data not defined

Attempt 3 So then I tried changing the doctype to "pandoctohtml", i.e., the following Weave command:

using Weave; weave("C:/Julia/test_interactive_weave.jl", out_path=:doc, doctype="pandoc2html")

When I use plotly() as the backend and pandoctohtml, I see the "got :html" error as before:

ERROR: only png or svg allowed. got: :html

Attempt 4 And when I use plotlyjs() and pandoctohtml, I see the same "data not defined" error:

ERROR: UndefVarError: data not defined

Package status The following is the output of using Pkg; Pkg.status()

  Status `C:\Users\jmarturano\.julia\environments\v1.1\Project.toml`
  [0825541b] ANOVA v0.2.0 [`C:\Users\jmarturano\.julia\dev\ANOVA`]
  [537997a7] AbstractPlotting v0.9.8
  [f9309374] ApplicationBuilder v0.4.0
  [b19378d9] ArrayFire v1.0.4
  [c52e3926] Atom v0.8.8
  [67c07d97] Automa v0.8.0
  [fbb218c0] BSON v0.2.3
  [ba4760a4] BayesNets v3.1.0
  [6e4b80f9] BenchmarkTools v0.4.2
  [00701ae9] BioAlignments v1.0.0
  [37cfa864] BioCore v2.0.5
  [7e6ae17a] BioSequences v1.1.0
  [a0d4ced5] BioServices v0.3.2
  [3c28c6f8] BioSymbols v3.1.0
  [fa51a905] BioTools v1.0.0
  [ad839575] Blink v0.12.0
  [e28b5b4c] Bootstrap v2.1.0
  [5f4fecfd] BrowseTables v0.3.0
  [336ed68f] CSV v0.5.9
  [aaaa29a8] Clustering v0.13.2
  [861a8166] Combinatorics v0.7.0
  [34da2185] Compat v2.1.0
  [8f4d0f93] Conda v1.3.0
  [3a865a2d] CuArrays v1.1.0
  [717857b8] DSP v0.5.2
  [d58978e5] Dagger v0.8.0
  [0fe7c1db] DataArrays v0.7.0
  [a93c6f00] DataFrames v0.19.1
  [864edb3b] DataStructures v0.17.0
  [7806a523] DecisionTree v0.8.3
  [0c46a032] DifferentialEquations v6.6.0
  [aaf54ef3] DistributedArrays v0.6.2
  [31c24e10] Distributions v0.21.1
  [a1bb12fb] Electron v1.0.0
  [89b67f3b] ExcelFiles v1.0.0
  [587475ba] Flux v0.8.3
  [da1fdf0e] FreqTables v0.3.1
  [38e38edf] GLM v1.1.1
  [8d5ece8b] GLMNet v0.4.2
  [28b8d3ca] GR v0.41.0
  [c91e804a] Gadfly v1.0.1
  [9bc6ac9d] GeneticVariation v0.4.0
  [c27321d9] Glob v1.2.0
  [aa1b3936] GraphIO v0.4.0
  [a2cc645c] GraphPlot v0.3.1
  [6735fb99] Hive v0.3.0
  [09f84164] HypothesisTests v0.8.0
  [7073ff75] IJulia v1.19.0
  [6a3955dd] ImageFiltering v0.6.4
  [916415d5] Images v0.18.0
  [c601a237] Interact v0.10.2
  [42fd0dbc] IterativeSolvers v0.8.1
  [6042db11] JDBC v0.4.1
  [033835bb] JLD2 v0.1.2
  [682c06a0] JSON v0.20.0
  [4076af6c] JuMP v0.19.2
  [a93385a2] JuliaDB v0.12.0
  [e5e0dc1b] Juno v0.7.0
  [031d7243] Keras v0.0.0 [`C:\Users\jmarturano\.julia\dev\Keras`]
  [5ab0869b] KernelDensity v0.5.1
  [b4fcebef] Lasso v0.4.0
  [093fc24a] LightGraphs v1.2.0
  [160ba089] LightGraphsMatching v0.1.0
  [4345ca2d] Loess v0.5.0
  [f0e99cf1] MLBase v0.8.0
  [add582a8] MLJ v0.2.3
  [da04e1cc] MPI v0.9.0
  [ee78f7c6] Makie v0.9.4
  [3bd8f0ae] Microbiome v0.4.0
  [e1d29d7a] Missings v0.4.1
  [ff71e718] MixedModels v1.1.6
  [f8716d33] MultipleTesting v0.4.1
  [6f286f6a] MultivariateStats v0.6.0
  [6ef6ca0d] NMF v0.4.0
  [be6f12e9] ODBC v0.8.4
  [47be7bcc] ORCA v0.2.1
  [a15396b6] OnlineStats v0.23.0
  [429524aa] Optim v0.19.2
  [9b87118b] PackageCompiler v0.6.4
  [eadc2687] Pandas v1.3.0
  [46a55296] ParquetFiles v0.2.0
  [f0f68f2c] PlotlyJS v0.12.5
  [91a5bcdd] Plots v0.26.0
  [f27b6e38] Polynomials v0.5.2
  [438e738f] PyCall v1.91.2
  [d330b81b] PyPlot v2.8.1
  [612083be] Queryverse v0.3.1
  [ce6b1742] RDatasets v0.6.3
  [b0e4dd01] RollingFunctions v0.6.2
  [c4c386cf] Rsvg v0.2.3
  [0aa819cd] SQLite v0.8.1
  [3646fa90] ScikitLearn v0.5.1
  [d2ef9438] Seaborn v0.4.1
  [47aef6b3] SimpleWeightedGraphs v1.1.0
  [e3819d11] Spark v0.4.0
  [60ddc479] StatPlots v0.9.2
  [2913bbd2] StatsBase v0.32.0
  [4c63d2b9] StatsFuns v0.8.0
  [2cb19f9e] StatsKit v0.3.0
  [3eaba693] StatsModels v0.5.0
  [8365b1bb] SubstitutionModels v0.4.0
  [fd094767] Suppressor v0.1.1
  [8a913413] Survival v0.1.0 [`C:\Users\jmarturano\.julia\dev\Survival`]
  [70df011a] TableReader v0.4.0
  [40c74d1a] TableView v0.4.0
  [1d978283] TensorFlow v0.11.0
  [a2db99b7] TextAnalysis v0.6.0
  [9e3dc215] TimeSeries v0.16.0
  [0796e94c] Tokenize v0.5.5
  [b8865327] UnicodePlots v1.1.0
  [0ae4a718] VegaDatasets v0.5.0
  [112f6efa] VegaLite v0.7.0
  [44d3d7a6] Weave v0.9.1
  [0f1e0344] WebIO v0.8.9
  [fdbf4ff8] XLSX v0.5.4
  [e88e6eb3] Zygote v0.3.2
  [8ba89e20] Distributed

I would appreciate any thoughts or help. Thank you for your time.

Masacroso commented 5 years ago

Related:

plotly backend to Plots not working in Jupyter notebook

josephmarturano commented 5 years ago

Today the Plots team released v0.26.1 for Plots.jl (link here). So now we can at least produce an interactive output using the plotly() backend to Plots, like so:

using Plots
plotly()
plot(randn(100))

When I run the above with Plots.jl 0.26.1, and then Weave to html:

using Weave; weave("C:/Julia/test_interactive_weave.jl", out_path=:doc, doctype="md2html")

I do get an interactive html output. So I am closing this issue. Thanks.

AsimHDar commented 4 years ago

I am getting issues too. When I put in the following:

using Plots
plotly()
plot(rand(10))

And then output via weave using:

weave((“doctest.jmd”), out_path=:pwd,doctype=“md2html”)

I get this: image

Error:

[ Info: Weaving chunk 1 from line 7
┌ Warning: ERROR: BoundsError occurred, including output in Weaved document
└ @ Weave ~/.julia/packages/Weave/UOxmI/src/run.jl:243
[ Info: Report weaved to test.html
[ Info: Weaving chunk 1 from line 7
┌ Warning: ERROR: BoundsError occurred, including output in Weaved document
└ @ Weave ~/.julia/packages/Weave/UOxmI/src/run.jl:243
[ Info: Report weaved to test.html

With plotlyjs():

image

See: https://discourse.julialang.org/t/trouble-getting-weave-to-output-plotly-based-plots-on-html-document/34244

jjallaire commented 3 years ago

I am seeing the same issues reported here (for both plotly() and plotlyjs()). The linked thread indicated that an update to Julia 1.2 fixed the issue however I am on Julia 1.5.3.

Here are the installed package versions:

[717857b8] DSP v0.6.8
[682c06a0] JSON v0.21.1
[9b87118b] PackageCompiler v1.2.3
[58dd65bb] Plotly v0.3.0
[a03496cd] PlotlyBase v0.4.2
[f0f68f2c] PlotlyJS v0.14.0
[91a5bcdd] Plots v1.8.1
[44d3d7a6] Weave v0.10.6

Any help or insight very much appreciated!

AsimHDar commented 3 years ago

Yeah it actually did stop happening for a while, I realize it was because of an update, but after I upgraded to Julia 1.5 it came up again. (Not sure if it is due to the Julia version).

JoaoAparicio commented 3 years ago

I'm getting the same thing

  [58dd65bb] Plotly v0.4.0
  [f0f68f2c] PlotlyJS v0.14.1
  [91a5bcdd] Plots v1.16.2
  [44d3d7a6] Weave v0.10.9
julia> versioninfo()
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, haswell)
Environment:
  JULIA_EDITOR = atom  -a
  JULIA_NUM_THREADS = 4
BenjaminDoran commented 2 years ago

I'm getting the same thing as well,

(testplotlydocs) pkg> status
     Project testplotlydocs v0.1.0
      Status `~/projects/testplotlydocs/Project.toml`
  [e30172f5] Documenter v0.27.14
  [f0f68f2c] PlotlyJS v0.18.8
  [f3b207a7] StatsPlots v0.14.33
  [44d3d7a6] Weave v0.10.10

julia> versioninfo()
Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.5.0)
  CPU: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)

Getting this during weave process of this code:

using StatsPlots
plotlyjs()

plot(rand(100))
┌ Info: Weaving chunk 3 from line 0
└   progress = 0.6666666666666666
┌ Warning: ERROR: UndefVarError occurred, including output in Weaved document
└ @ Weave ~/.julia/packages/Weave/lQPaO/src/run.jl:224

It works in the notebook in vscode, but not when trying to weave

the resulting html document showing, same result happens for markdown output as well.

image