flekschas / jupyter-scatter

Interactive 2D scatter plot widget for Jupyter Lab and Notebook. Scales to millions of points!
https://jupyter-scatter.dev
Apache License 2.0
337 stars 14 forks source link

Is there anyway for me to get this out of a jupyter notebook (at least a bit) #124

Closed GeorgePearse closed 4 months ago

GeorgePearse commented 4 months ago

I want to hand this over to non-technical users, and stitch it together with a few python workflows.

What's my best option for this? Should I try to productionise the jupyter notebook as a web app?

Could I embed it in anything else?

flekschas commented 4 months ago

I think it depends a bit on what you're trying to accomplish.

Jupyter Scatter uses regl-scatterplot under the hood (you could almost go as far an call Jupyter Scatter just an API layer for integration with the Jupyter and Pandas world) so it's definitely possible to replicate the interface in a web app. However, this requires fully understanding regl-scatterplot's API (which isn't the most intuitive I must confess 😅).

A more lightweight option would be voila (streamlit is unfortunately not an option as it does not support ipywidgets). I personally haven't used voila before but in a quick test it seems to render the notebook with jscatter just fine.

You can also use nbconvert to turn your notebook into a sharable HTML page if you don't need to run any computation interactively. For now just keep in mind of the selection limitation when using nbconvert.

@manzt Do you by chance know of other cool libraries for turning a notebook into a deployable web app?

GeorgePearse commented 4 months ago

This is a great answer @flekschas really appreciate it.

Had just started looking into whether voila would do the trick.

GeorgePearse commented 4 months ago

Getting it running with voila was pretty incredibly easy.

image

manzt commented 4 months ago

@manzt Do you by chance know of other cool libraries for turning a notebook into a deployable web app?

There are a couple dashboarding frameworks with support for widgets. I haven't built anything that substantial with any.

I believe solara is the most oriented around widgets (cc: @maartenbreddels), and allows for prototyping with notebooks.

maartenbreddels commented 4 months ago

Thank you for the mention Trevor!

Using this example:

import jscatter

import numpy as np
import pandas as pd

# Just some random float and int values
data = np.random.rand(500, 4)
df = pd.DataFrame(data, columns=['mass', 'speed', 'pval', 'group'])
# We'll convert the `group` column to strings to ensure it's recognized as
# categorical data. This will come in handy in the advanced example.
df['group'] = df['group'].map(lambda c: chr(65 + round(c)), na_action=None)

page = jscatter.plot(data=df, x='mass', y='speed')

This can be run using solara run app.py and it will pick up the page variable/widget.

Or you can run and edit this code snippet at PyCafe

A bit more complex example, although see the comment/TODO

flekschas commented 4 months ago

Wow nice! Thanks for sharing the snippets!

@GeorgePearse Does that help you getting started?

GeorgePearse commented 4 months ago

@flekschas got a silly number of good options now, tooling in this space has got so much better over the last few years.

flekschas commented 4 months ago

Awesome! I'll close the ticket then but please feel free to reopen it if you have more questions.