solara
solara copied to clipboard
feature request: Allow launching the Solara server via python app.py
Currently, there are 2 ways to run the Solara app:
solara run app.py- Launch a Jupyter notebook server, then execute the cells in app.py
My request is to have an option to do python app.py so that it is easier to document. Though, saying solara run app.py already works. Perhaps a better use (though this is not my use case at the moment) case would be to have another web server code that launches the Solara server programmatically.
Though a subprocess.Popen(["solara", "run", "app.py"]) would have worked too.
One use case for adding this functionality: it may make it easier to produce an pyinstaller executable from code employing solara.
In https://github.com/widgetti/solara/pull/716 (pyinstaller PR) we use
@click.command()
@click.option(
"--port",
default=int(os.environ.get("PORT", 0)),
help="Port to run the server on, 0 for a random free port",
)
def run(port: int, webview: bool = False):
if "SOLARA_APP" not in os.environ:
os.environ["SOLARA_APP"] = "sample_app"
import solara.server.starlette
server = solara.server.starlette.ServerStarlette(host="localhost", port=port)
print(f"Starting server on {server.base_url}")
server.serve_threaded()
server.wait_until_serving()
server.join()
See: https://github.com/widgetti/solara/pull/716/files#diff-d0b5daeae94ba7a7305fb2cc670f3670739192411f2b867befe0f7eaea562a44
I hope that helps for now. It's not a documented API, but we've been using it for quite a while and I'll try to not break it without reason.
I can imagine we'll add a solara.serve(..) in the future.
Thanks for sharing, will certainly look into it!
For Mesa, this would be a really useful feature. So if at one point its considered making this a stable and documented feature, I would support it.
In general, we're looking at how to interface (ideally back and forth) between Solara and the Python interpreter. See for some details:
- https://github.com/projectmesa/mesa/issues/2176
@maartenbreddels what do you think of the feasibility of being able to go back and forth between a Solara component and other Python instances? Ideally both could control each other, but that might get quite complicated.
Having two distinct modes would already be useful:
- Model controls visualization progress/updates
- Visualization controls model steps/functions
(CC @Corvince)
I think that is quite feasable (if I understand you correctly).
The problem I see, is that solara needs to know (or be told) when to update something. If you use reactive variables, that makes it easy, you get this for free. However, that means a dependency of your model classes on solara itself.
Otherwise, you'd have to use something like traitlets etc (and think about multi-user, if you run solara out of the notebook, in solara server)