Select default browser to display PlotlyLight.Plot()

One important feature for a plot package the produces interactive HTML-output is for me the feature to select the default browser to display my HTML-figure. Below a code snippet for the package plotlylight-jl:

using PlotlyLight, Cobweb
# ----------------------------------------------------------------------------------------------------------------------------------
# --- PlotlyLight Repository:   https://github.com/JuliaComputing/PlotlyLight.jl
# --- documentation:            https://plotly.com/javascript/
# ----------------------------------------------------------------------------------------------------------------------------------
# --- proposal to make default browser selectable:
struct MyDisplay <: AbstractDisplay end

pushdisplay(MyDisplay())

function Base.display(::MyDisplay, _myplot::PlotlyLight.Plot) # DataType / # PlotlyLight.Plot  
    Cobweb.save(Cobweb.Page(_myplot)) # overwrite "index.html"
    _filename = joinpath(Cobweb.DIR, "index.html")
    run(`cmd /c start msedge.exe $_filename`)
end

# --- Example Figure, first change template:
# PlotlyLight.Preset.Template.plotly_dark!()

# --- Make plot
p = PlotlyLight.Plot(x = 1:20, y = cumsum(randn(20)), type="scatter", mode="lines+markers");

# --- Make changes
p.layout.title.text = "My Title!"

# --- `display(p)` to see the updated plot
display(p)

source: issues/26

2 Likes