solara icon indicating copy to clipboard operation
solara copied to clipboard

Use in static documentation sites?

Open NickCrews opened this issue 2 years ago • 3 comments

I'm really impressed with solara so far. Thank you so much for your time.

I have a project which has a static site for documentation. I have some example notebooks in there that are run to generate the HTML using mkdocs and mkdocs-jupyter. Before, I was using plain old altair charts. But now I want to make them more interactive with solara components. However, now the staticly built example pages don't render the widgets correctly, because there is no backend to connect to. It says Cannot show widget. You probably want to rerun the code cell above (Click in the code cell, and press Shift+Enter ⇧+↩). The example page I'm taking about is here (cell number 3, where it uses distribution_dashboard())

Do you have suggestions as to how I can present these examples with the live widgets still working? Can we make solara work with jupyterlite? If I try pip installing Solara in jupyterlite there are a few dependencies like watchdog that don't have wasm wheels and this Solara fails to install. Can we make these deps optional (no filesystem in jupyterlite anyways...) or otherwise fix them?

Should I put these examples in a binder or colab instance and just link to them? It would be very nice if I didn't have to link out, and the examples could just live on the static github pages site.

NickCrews avatar Jan 07 '24 03:01 NickCrews

Over at Mesa we're working on a Solara-based front-end. We're now considering deploying examples and tutorials using JupyterLite, which uses Pyodide under the hood.

We would love Solara to support this environment, since most our users are modellers but not necessarily. It would lower the barrier to entry significantly if they could start with running examples and models from the browser.

EwoutH avatar Jan 09 '24 08:01 EwoutH

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.

We are also working on something that enables you to run solara conveniently in the browser, if jupyter lite does not suite your need, please contact me at [email protected] if you want to do user-testing.

Regards,

Maarten

maartenbreddels avatar Apr 08 '24 19:04 maartenbreddels

I tested solara in Jupyterlite (https://jupyterlite.readthedocs.io/en/stable/_static/lab/index.html) with the following code:

%pip install "solara-ui[all]"
import solara

# Declare reactive variables at the top level. Components using these variables
# will be re-executed when their values change.
sentence = solara.reactive("Solara makes our team more productive.")
word_limit = solara.reactive(10)


@solara.component
def Page():
    # Calculate word_count within the component to ensure re-execution when reactive variables change.
    word_count = len(sentence.value.split())

    solara.SliderInt("Word limit", value=word_limit, min=2, max=20)
    solara.InputText(label="Your sentence", value=sentence, continuous_update=True)

    # Display messages based on the current word count and word limit.
    if word_count >= int(word_limit.value):
        solara.Error(f"With {word_count} words, you passed the word limit of {word_limit.value}.")
    elif word_count >= int(0.8 * word_limit.value):
        solara.Warning(f"With {word_count} words, you are close to the word limit of {word_limit.value}.")
    else:
        solara.Success("Great short writing!")


# The following line is required only when running the code in a Jupyter notebook:
Page()

And I met the issue of

Traceback (most recent call last):
  File "/lib/python3.12/site-packages/reacton/core.py", line 1707, in _render
    root_element = el.component.f(*el.args, **el.kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-f54307a02d67>", line 13, in Page
    word_count = len(sentence.value.split())
                     ^^^^^^^^^^^^^^
  File "/lib/python3.12/site-packages/solara/toestand.py", line 101, in value
    return self.get()
           ^^^^^^^^^^
  File "/lib/python3.12/site-packages/solara/toestand.py", line 366, in get
    return self._storage.peek()
           ^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.12/site-packages/solara/toestand.py", line 235, in peek
    return self.get()
           ^^^^^^^^^^
  File "/lib/python3.12/site-packages/solara/toestand.py", line 238, in get
    scope_dict, scope_id = self._get_dict()
                           ^^^^^^^^^^^^^^^^
  File "/lib/python3.12/site-packages/solara/toestand.py", line 223, in _get_dict
    import solara.server.kernel_context
  File "/lib/python3.12/site-packages/solara/server/kernel_context.py", line 27, in <module>
    from . import kernel, kernel_context, websocket
  File "/lib/python3.12/site-packages/solara/server/kernel.py", line 12, in <module>
    import ipykernel.kernelbase
ModuleNotFoundError: No module named 'ipykernel.kernelbase'

Please check. I wish solara support Jupyterlite.

MRYingLEE avatar Aug 07 '24 02:08 MRYingLEE