I’m currently building a little application with Reflex and would like to pass some custom parameters when running it. Those parameters are needed by my application, i.e. not directly related to Reflex.
Without Reflex I would just pass them via the command line and use argparse, but I guess with reflex run
that’s not so easy. Is there some nice way how I can pass arguments without hard-coding them?
I would recommend setting up custom configuration knobs in rxconfig.py
and then setting those with environment variables. This will allow you to leverage our hosting service and docker examples without having to modify the reflex run
command.
import reflex as rx
class CustomConfig(rx.Config):
error_threshold: int = 0
config = CustomConfig(
app_name="my_app",
)
Then run it like
ERROR_THRESHOLD=34 reflex run
And access it like
rx.heading(f"Threshold: {rx.config.get_config().error_threshold}"),
Some limitations are that it doesn’t support casting complex types from the environment variable, like list
or dict
.
Perfect, that’s the kind of solution I was looking for.
Thanks!