Get help from the marimo community

Updated 3 weeks ago

What's the expected behaviour when running notebooks that contain UI elements as scripts?

Hey, I've got some notebooks where I use UI components (selectors) that have some default values. I'd expect the default behaviour is that the variables assigned to those components would simply use those values when running the notebooks as scripts but I am unsure that's the expected/designed behaviour but i don't see my script returning an error or warning either
l
S
M
7 comments
ah, actually, I've got a run_button which would explain the script hanging in python mode.

A super neat feature would be if the ui element behave as CLI menus when ran as scripts if they don't contain a default value or are omitted or are interactice components such as run_button, is it clear what I mean?
not quite sure I follow, do you mean it should prompt the user something in the CLI to continue running the script?
like the output of this script for example:
Plain Text
import click

@click.command()
def menu():
    """Simple number-based selection menu using Click."""
    # Define options
    options = {
        1: "Option One",
        2: "Option Two",
        3: "Option Three",
        4: "Exit"
    }
    
    while True:
        # Display menu
        click.echo("\n===== MENU =====")
        for num, text in options.items():
            click.echo(f"{num}. {text}")
        click.echo("===============")
        
        # Get selection
        choice = click.prompt("Enter selection", type=int)
        
        # Process selection
        if choice in options:
            if choice == 4:
                click.echo("Exiting. Goodbye!")
                break
            click.echo(f"You selected: {options[choice]}")
        else:
            click.echo("Invalid selection")

if __name__ == "__main__":
    menu()


but it would be involved to map every ui to a click or similar interface
You could use app_meta to programmatically configure how cells would be run. Something like this using your example.
Plain Text
if mo.app_meta().mode == 'script':
   menu()


But I get that you want all ui elems to be mapped to a script interface, yeah it's interesting, would need some work..
sudddenly marimo apps would also become cli scripts/tool, I think it would be powerful but it almost feels like a new platform marimo output so not sure it's aligned with marimo's current goals, thoughts @Myles Scolnick ?
yea it’s possible some ui elements could be displayed in the terminal (maybe by an argument). Like a table or chart. I build a lot of my apps with run button to use it in an app mode and then the snippet from @Shahmir to run as a script, and then include print statements throughout
Add a reply
Sign up and join the conversation on Discord