Skip to content
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

embeddable html show for performance in Pluto #3559

Merged
merged 1 commit into from
Jun 9, 2021

Conversation

fonsp
Copy link
Contributor

@fonsp fonsp commented Jun 8, 2021

Standalone/embeddable html in Base.show

Currently, the Base.show(io::IO, m::MIME"text/html", p::Plot{PlotlyBackend}) method outputs a standalone HTML document, i.e.

<html>
<head>
...
</head>
<body>
...
</body>
</html>

which means that it cannot (correctly) be embedded inside HTML output, without using an <iframe>.

This is why text/html show methods in Julia are generally not standalone pages, but HTML snippets. A good example is Plots.jl with the GR backend, where Base.show(io::IO, m::MIME"text/html", p::Plot{PlotlyBackend}) outputs a bare <img> or <svg> tag, not wrapped inside <html>.

Other examples are DataFrames.jl (bare <table>) and the Markdown stdlib (bare <div>).

<script> tags do not need to be placed inside a <head> to load, which is why this PR replaces the show method with a simpler one.

Before

Because every cell output is a standalone HTML document, Pluto needs to create a new iframe to render the subpage in, causing notable flickering.

Schermopname.2021-06-08.om.20.22.03.mov

After

Schermopname.2021-06-08.om.20.25.13.mov

Other environments still work

VS Code

image

Jupyter

Schermafbeelding 2021-06-08 om 20 42 17

Static

Environments that generate static HTML will be unaffected, including Franklin and Literate.

Example code

(For Pluto and Jupyter)

begin
	import Pkg
	Pkg.activate(mktempdir())
	Pkg.add([
			Pkg.PackageSpec(url="https://github.com/fonsp/Plots.jl", rev="embeddable-plotly-html"),
			Pkg.PackageSpec(name="PlutoUI"),
		])
	using PlutoUI
	using Plots
	plotly()
end
plot(sin.(.01 .* (1:x)))

@fonsp fonsp changed the title embeddable html show for significant performance boost embeddable html show for performance in Pluto Jun 8, 2021
@fonsp
Copy link
Contributor Author

fonsp commented Jun 8, 2021

CI failure seems unrelated

@codecov
Copy link

codecov bot commented Jun 8, 2021

Codecov Report

Merging #3559 (d230f9b) into master (019a742) will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3559      +/-   ##
==========================================
- Coverage   64.50%   64.48%   -0.02%     
==========================================
  Files          27       27              
  Lines        6623     6623              
==========================================
- Hits         4272     4271       -1     
- Misses       2351     2352       +1     
Impacted Files Coverage Δ
src/backends/gr.jl 87.56% <0.00%> (-0.10%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 019a742...d230f9b. Read the comment docs.

@isentropic
Copy link
Member

Looks good to me

@BeastyBlacksmith BeastyBlacksmith merged commit 203af85 into JuliaPlots:master Jun 9, 2021
@fonsp
Copy link
Contributor Author

fonsp commented Jun 10, 2021

@isentropic @BeastyBlacksmith I could do further Pluto-plotly optimizations, including:

Some discussion here: https://discourse.julialang.org/t/pluto-plots-with-plotlybase-plotlyjs-with-working-static-html-export/61730/7

Demo notebooks:

Implementing this would mean using some code (if isdefined(Main, :PlutoRunner) ...) to check for Pluto. Would that PR be welcome?

@fonsp fonsp deleted the embeddable-plotly-html branch June 10, 2021 23:04
@BeastyBlacksmith
Copy link
Member

That'd definitely welcome.
If possible, we'd like to have the backend code generic and code that is specific to certain editors is in output.jl (e.g. for the juno plot pane). That's no hard requirement though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants