S
SolaraRazzle

Running a file vs running a module

Hello! I am trying to get solara up and running for use with mesa but am having some issues. I structured my code as a python package and would like to be able to run solara run my-package (or even better, just my-package) in the cli to start the server. Currently, running solara run __main__.py works, but for some reason running solara run my-package does not. Adding a print statement to __main__.py, I can see it being printed but solara does not appear to be able to find the route:
Page not found by Solara router
Page not found by Solara router
My __main__.py looks like this:
from mesa.experimental import JupyterViz

print("Hello")

page = JupyterViz(
MyModel,
model_params,
measures=[],
name="Test Model",
agent_portrayal=agent_portrayal,
)
from mesa.experimental import JupyterViz

print("Hello")

page = JupyterViz(
MyModel,
model_params,
measures=[],
name="Test Model",
agent_portrayal=agent_portrayal,
)
Is there a way to just "run" the page, similar to Flask's app.run() and if not, how can I make the solara CLI tool pick up the page even when running the module instead of the __main__.py directly? Thanks
E
EdgeofChaos3d ago
@Razzle I work on mesa and you can runn and app form the command line using solara run <name>.py and exmaple is located in the mesa example repo boltzmann_wealth_experimental
GitHub
mesa-examples/examples/boltzmann_wealth_model_experimental at main ...
Seminal agent-based models developed using Mesa. Contribute to projectmesa/mesa-examples development by creating an account on GitHub.
R
Razzle3d ago
Thank you! I understand that, I am looking for how to integrate this "single-file" approach into a python pacakge, so that I don't have to ship the python file to the end user, and can just instruct them to run pip install mypackage, followied by solara run mypackage
M
MaartenBreddels3d ago
Did you try to put it in my-package/__init__.py ?
R
Razzle3d ago
Yes, I still get a Page not found by Solara router :(
M
MaartenBreddels3d ago
if solara run solara.website.pages runs, then you should check what the difference is. One thing I wonder about is if you also have a directory my-package? Although, that should give you the same result. Just as a sanity check, please define a Page component (since in the above i see a page element being used, which seems to be the only difference I think)
Want results from more Discord servers?
Add your server
More Posts
Multiple different solara apps under Fastapi endpoints?Hi, I can follow the explanation from the docs to integrate one solara app into an existing FastAPUsing existing plotly widget to update figuresWith go.FigureWidget it is possible to update the data/properties of a figure without redrawing it. Multipage tab colorIs there a way to set the color of the page-tab text in a multipage application? I'm interested in sIs there a way to filter the options in a select elementI want to use a select element but I have a rather big amount of options in my list, so I was wonderTrying to understand state managementIf I have a reusable component with an internal state `value = use_reactive(42)` linked to an `IntSlCan't cancel running @task?I've got a button triggered function that executes a for loop over a data set list and makes an API Possible to use custom vue components in `component_vue`?In `Voila`, it was possible to register custom vue-only components by registering them with `ipyvue`Plotly FigureWidget axes do not reset ranges within solara's render contextUpon applying an effect to set `autorange=True` to a figure with `autorange='reversed'`, the Figure Interactive layoutThere are a couple of defunt projects out there like jupyter-flex and jupyter-dashboard for creatingUsing vue libraries with ipyvuetify & solaraIs it naive to think vuepdf should work out of the box with a ipyvuetify template? I've stripped thInteract with `Layout` defined in another fileIn a file with a defined `Page` solara component, I can import a defined `Layout` specified in anothuse_thread eats logs?When an exception is thrown in a function run from use_thread it seems I don't get any log (logging