solara icon indicating copy to clipboard operation
solara copied to clipboard

Import and use solara without solara.server

Open Corvince opened this issue 1 year ago • 6 comments

Every few months I come back to solara and test if it is installable on JupyterLite, but the process always becomes very hacky still.

Now I decided to take a closer look at the culprits. I think it is somewhat obvious that solara.server is the main problem, so I took the look on the current state on how deeply integrated it is. So my approach was to first delete the solara.server folder and then proceed to test what needs to change to make it work in Jupyter (normal one, not lite). Here are my findings in the order they appeared:

  1. solara.components.style Here the server is imported to check if is running in production mode - and if yes enable hot reload
  2. solara.solara.init The initalisation of the new Theme feature creates a Singleton (of solara.toestand) that does some cleanup (?) on_kernel_start
  3. solara.lab.init This also imports the on_kernel_start function, but doesn't use it at all.
  4. solara.components.applayout This file imports solara.server just to call solara.server.telemetry.jupyter_start()

And thats it! I think this isn't too bad at all. My assessment on how easy it is to fix them. 1. - easy Hot reload isn't necessary in Jupyter. 2. I am clueless about this one, since I am not sure what it actually does 🙃. 3. Trivial - just remove the import. 4. Depends - A clean solution probably requires some restructering

I would be happy to help implement the changes. I saw that there is already a _using_solara_server function that checks for the existence of solara.server. The quick solution for 1) and 4) could be to just use this to deactive the features when solara.server is not available - if this is fine as a first solution I am happy in submitting a PR (and remove 3). I would just need some more information on 2).

When these changes are applied it should be possible to use solara with JupyterLite by just mocking the unavailable dependencies. So this could be possible pretty soon, before solara is split into solara-server and solara-ui (I read somewhere this is one of the plans, but probably takes some more time).

Corvince avatar Mar 08 '24 19:03 Corvince

Hi,

Can I start by asking why you want to run solara in Jupyter lite (genuine curiosity!). Do you want to run a solara app for people to use for instance, or do you want other to use solara in a notebook? Or only for yourself maybe?

Yes, ideally we make the split between solara-ui and solara-server, especially because of the dependencies. How do you currently solve it with the dependencies?

  1. I think we do want hot reloading in jupyter, so we can do a check (only when in server AND production, we do not use hot reload) 2+3. I think if we move on_kernel_start into a solara.lab module, then it's basically a no-op in Jupyter(Lite), which is what we want I think and solara-server can actually use the callbacks. It cannot be removed, it's imported there because that is where we expose the API call. 4 I'll see if this can be split into two modules.

If you can open a PR for 1 and 2+3 separately that would be great!

Regards,

Maarten

maartenbreddels avatar Mar 09 '24 10:03 maartenbreddels

Hi, thanks for the reply.

My main use case is creating a template to make it super easy for people to share models created with Mesa. So similar to how the JupyterLite Repo itself is a GitHub template, I want to do the same for a basic mesa ABM and a visualization frontend with Solara hosted statically on GitHub Pages. Technically, Jupyter Lite would not be required, but I figured it would be the easiest way for now.

  1. Oh, I didn't know it is possible to use hot-reload while working in jupyter, thats cool.
      1. Ah, I see. I will see what I can do about a PR for that!

Corvince avatar Mar 11 '24 13:03 Corvince

We are working on a pyodide based solution internally actually, do you mind emailing me at [email protected] so I can show you some (currently) private work?

maartenbreddels avatar Mar 11 '24 16:03 maartenbreddels

@Corvince @maartenbreddels I'm also interested in this issue and would be happy to help / test if needed

albop avatar Mar 28 '24 08:03 albop

@albop if you are intersted in the above, please send me an email.

Also, I am working in https://github.com/widgetti/solara/pull/585 to split off solara-ui and solara-server This will enable a much lighter weight installation for the Jupyter notebook.

maartenbreddels avatar Apr 05 '24 20:04 maartenbreddels

Note that solara 1.31 has done the split into solara-ui and solara-server, see https://solara.dev/documentation/getting_started/installing

solara-ui should work in jupyter lite without problems.

maartenbreddels avatar Apr 08 '24 19:04 maartenbreddels