malolo
malolo7mo ago

Modify UI elements

Is it possible to modify the attributes of UI elements? For instance, to change the range of a slider:
No description
6 Replies
Akshay
Akshay7mo ago
Typically you’d hook that up with reactivity/the dag structure of your notebook, with start/stop depending on some other variable. If you really need to do it programmatically you can look at mo.state(), but that significantly increases complexity and is typically unnecessary. What’s the context / what are you trying to achieve?
malolo
maloloOP7mo ago
I want the slider to represent a number of available files, and I'm aiming to create a filtering control, so when the filter applies, the slider's stop would go down to represent the filtered set. so if assign stop to a variable or function, it'll automatically bind it?
Akshay
Akshay7mo ago
Cells in the notebook are wired up based on variable definitions and references. In separate cells: filter_value = … stop = calculate_stop(filter_value) slider = mo.ui.slider(start=1, stop=stop) I recommend running marimo tutorial intro, marimo tutorial dataflow, and marimo tutorial ui at your command line. Should take maybe 10 min to play with the tutorials, after which marimo will make a lot of sense. If you don’t have much time then just try the intro tutorial.
malolo
maloloOP7mo ago
I see, thanks for the example! I did look at the tutorials but didn't realize that I could also do that with attributes, not just with values. although the label example should've given it away =p
Akshay
Akshay7mo ago
Ah sorry, didn’t know you looked at the tutorials Assigning to attributes won’t trigger reactivity — has to be to global var
malolo
maloloOP7mo ago
it's all good, still getting used to it but getting there: https://marimo.app/l/i7aa1x