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

📈 Pluto object viewer as embeddable element #1126

Merged
merged 19 commits into from
Apr 29, 2021
Merged

Conversation

fonsp
Copy link
Owner

@fonsp fonsp commented Apr 26, 2021

You can now use Pluto's object viewer inside custom HTML output, making things possible like: interactive table viewer on the left half of a cell, plot on the right. The embedded viewer is available inside notebooks as:

embed_display(x)

and inside packages as:

if isdefined(Main, :PlutoRunner) && isdefined(Main.PlutoRunner, :embed_display)
	# if this package is used inside Pluto, and Pluto is new enough
	Main.PlutoRunner.embed_display(x)
else
	x
end

image

let
	left = DataFrame(rand(30,3),:auto)
	right = Matrix(left) |> plot
	
	@htl("""

	<div style="display: flex;">
		
	$(embed_display(left))
	$(embed_display(right))
		
	</div>

	""")
end

It's interactive, and you can click on "More"

Schermopname.2021-04-29.om.15.37.14.mov
let
	left = rand(50)
	right = left |> plot
	
	@htl("""

	<div style="display: flex;">
		
	<div style="max-width: 50%; overflow: auto;">
		$(embed_display(left))
	</div>
	$(embed_display(right))
		
	</div>

	""")
end

You can also use it inside Markdown

image

TODO:

  • I had to import preact directly from esm.sh to get fields that are hidden in the htm bundle. This probably won't work in China, so either find a way to get it with jsdelivr or Artifacts to proxy&cache CDNs #241 . I think the easiest way is to create a new repo containing just https://github.com/fonsp/Pluto.jl/blob/pluto-display-custom-element/frontend/imports/Preact.js and then call deno bundle on that, and store the bundle in the same repo
  • The preact contexts don't work for custom elements inside preact components, which means that bonds don't work showing more items doesn't work
  • Add helper function to PlutoRunner
  • Scripts are executed twice?
  • How to reuse the preact state?

This is achieved in combination with #1124

Demo and test notebook

https://github.com/fonsp/Pluto.jl/blob/main/sample/test_embed_display.jl

@fonsp fonsp marked this pull request as ready for review April 26, 2021 23:49
@fonsp fonsp changed the title Pluto object viewer as <pluto-display> web element 📈 Pluto object viewer as <pluto-display> web element Apr 26, 2021
@fonsp fonsp changed the title 📈 Pluto object viewer as <pluto-display> web element 📈 Pluto object viewer as <pluto-display> custom element Apr 26, 2021
@fonsp
Copy link
Owner Author

fonsp commented Apr 26, 2021

This will fix Roger-luo/Configurations.jl#34

@fonsp fonsp changed the title 📈 Pluto object viewer as <pluto-display> custom element 📈 Pluto object viewer as embeddable element Apr 29, 2021
@fonsp fonsp merged commit 38577fe into main Apr 29, 2021
@fonsp fonsp deleted the pluto-display-custom-element branch April 29, 2021 19:29
@fonsp
Copy link
Owner Author

fonsp commented May 2, 2021

@andreypopp I was having a quick look at your fork and this PR might be of interest to you.

Note the "Persistance" in the test notebook on the bottom (still work in progress). This means that you can implement things like HBox inside user-code, it does not need to be part of Pluto's editor VDOM.

I am planning on adding hbox, vbox, grid as a new submodule PlutoUI.Layout, WIP code is currently here: https://github.com/fonsp/disorganised-mess/blob/main/Layout.jl I wrote that notebook before implementing this PR, but it would be interesting to combine the two.

@fonsp fonsp mentioned this pull request May 4, 2021
@schneiderfelipe
Copy link
Contributor

@fonsp Do you think this can help improve JuliaPluto/PlutoUI.jl#102?

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

Successfully merging this pull request may close these issues.

2 participants