-
Notifications
You must be signed in to change notification settings - Fork 115
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
Feature request: display interactive figures given by Plots.jl with PlotlyJS backend just like fdplotly #890
Comments
I come up another implementation idea that maybe a ```julia:pyplot1
using Plots
plotlyjs()
p= plot(sinc)
savefig(joinpath(@OUTPUT, "sinc.json")) # hide
```
\fig{sinc} Not test yet. Just an idea. |
I'm glad you're experimenting with this and what you're doing sounds pretty useful! as you noticed though typing shouldn't be in the package because I don't want
I don't have much time right now to check this in more details but will do so next week, just sharing some early notes that you might find useful |
Maybe, this could be solved via |
After doing some experiment, I found several things. Let me first post the the experimental solution now: I choose to first save the Plots file in json file and then plot it with a helper function written in Javascript. In {{if hasplotly}} <script src="/libs/plotly/plotly.min.js"></script>
<script>
const PlotlyJS_json = async (id, url) => {
fetch(url)
.then(response => response.json())
.then(fig => {
CONTAINER = document.getElementById(id);
Plotly.newPlot(CONTAINER, fig.data, fig.layout)
});
// Here is another way to implement the same feature using async and await
// response = await fetch(url); // get file
// fig = await response.json(); // convert it to json
// CONTAINER = document.getElementById(id);
// Plotly.newPlot(CONTAINER, fig.data, fig.layout, fig.config);
};
</script>
{{end}} Another Julia helper function import Random
"""
Display a Plots plot `p` created by the PlotlyJS backend
"" is the default size of Plots
import Plots
plotlyjs(); # use PlotlyJS as the backend of Plots
p = Plots.plot(sinc)
Plots.savefig(p, joinpath(@OUTPUT, "sinc.json"))
# json_path = ...
interactive_plot_json(json_path)
"""
function interactive_plot_json(src ; id="fdp"*Random.randstring('a':'z', 3),
style="")::Nothing
io = IOBuffer()
println(io, """~~~""")
print(io, """
<div id="$id" style="$style"></div>
<script>
"use strict"
PlotlyJS_json('$id', '$src');
</script>
""")
println(io, """~~~""")
println(String(take!(io)))
return nothing
end ```julia:intplot
using Plots
plotlyjs(); # use PlotlyJS as the backend of Plots
# need a way to find where the picture is
interactive_plot_json("/assets/blog/2021/09/07_PlotlyJS/code/output/pp.json";style="")
```
\textoutput{intplot}
Note: this implementation is definitely not the best way. I think a better way is to integrate it in to I also find that
|
Hi... I have a question, I tried this and when I was running it locally the interactive plot is showing but once I deploy it to gitpages, the interactive plot is not showing. Can someone help? |
When
PlotlyJS.jl
is used, a beautiful interactive plot can be display with the helper functionfdplotly
.But I couldn't find a build-in method to show interactive
Plots.jl
figures withplotlyjs()
backend just like whenPlotlyJS.jl
is used directly. (Don't know whether that is the case.)So I have implemented a helper function myself. It works but I think it is not so good that several problem has to be solved.
It can be used like this in
Franklin.jl
Several Problem should be solved:
json
inPlots.jl
directly save it to a file which I think is unnecessary.p
. It should be something likep::Plots.Plot{Plots.PlotlyJSBackend}
. But when this function is placed insrc/manager/extra.jl
, it can't findPlots
.The text was updated successfully, but these errors were encountered: