jupyter-scatter icon indicating copy to clipboard operation
jupyter-scatter copied to clipboard

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

Open GeorgePearse opened this issue 1 year ago • 7 comments
trafficstars

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?

GeorgePearse avatar May 09 '24 19:05 GeorgePearse

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?

flekschas avatar May 10 '24 00:05 flekschas

This is a great answer @flekschas really appreciate it.

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

GeorgePearse avatar May 10 '24 08:05 GeorgePearse

Getting it running with voila was pretty incredibly easy.

image

GeorgePearse avatar May 10 '24 08:05 GeorgePearse

@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.

  • https://github.com/holoviz/panel
  • https://github.com/widgetti/solara
  • https://github.com/posit-dev/py-shiny

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

manzt avatar May 12 '24 01:05 manzt

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

maartenbreddels avatar May 13 '24 14:05 maartenbreddels

Wow nice! Thanks for sharing the snippets!

@GeorgePearse Does that help you getting started?

flekschas avatar May 14 '24 00:05 flekschas

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

GeorgePearse avatar May 15 '24 10:05 GeorgePearse

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

flekschas avatar May 16 '24 00:05 flekschas