Open rht opened 1 year ago
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()
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:
@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:
(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)
Currently, there are 2 ways to run the Solara app:
solara run app.py
My request is to have an option to do
python app.py
so that it is easier to document. Though, sayingsolara 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.