dbunskoek
dbunskoek
Mmarimo
Created by dbunskoek on 6/18/2024 in #archived-help-and-support
But I could just store the values, right
Please let me know what you think, or if I'm missing something 🙏
4 replies
Mmarimo
Created by dbunskoek on 6/18/2024 in #archived-help-and-support
But I could just store the values, right
For the record, I managed to make it work like this:
def create_get_item_state(index, key, default=None):
def get_item_state(default):
if index >= len(items_state):
items_state.append({
key: default
})
else:
if key not in items_state[index]:
items_state[index][key] = default
item = items_state[index]
return item[key]

return get_item_state

def create_set_item_state(index, key):
def set_item_state(value):
item = items_state[index]
item[key] = value

return set_item_state

def create_item(index):
item = mo.ui.dictionary(
{
"component": mo.ui.text(value=create_get_item_state(index, "component")("Onderdeel"), on_change=create_set_item_state(index, "component")),
"complexity": mo.ui.number(start=0, stop=1000, value=create_get_item_state(index, "complexity")(100), on_change=create_set_item_state(index, "complexity")),
"state": mo.ui.number(start=0, stop=10, value=create_get_item_state(index, "state")(8), on_change=create_set_item_state(index, "state")),
"influence": mo.ui.slider(start=0, stop=100, step=5, value=create_get_item_state(index, "influence")(50), on_change=create_set_item_state(index, "influence")),
}
)
return item

items = mo.ui.array([create_item(i) for i in range(num_items.value)])

mo.md(
"""
| Component | Complexity | State | Influence (in vs outside) |
| :- | -: | :- | :- |
"""
+ "\n".join(
[
f"""
| {item['component']}
| {item['complexity'].style({"width": "80px"})}
| {item['state'].style({"width": "80px"})}
| {item['influence']}
""".replace("\n", "")
for item in items
]
)
)
def create_get_item_state(index, key, default=None):
def get_item_state(default):
if index >= len(items_state):
items_state.append({
key: default
})
else:
if key not in items_state[index]:
items_state[index][key] = default
item = items_state[index]
return item[key]

return get_item_state

def create_set_item_state(index, key):
def set_item_state(value):
item = items_state[index]
item[key] = value

return set_item_state

def create_item(index):
item = mo.ui.dictionary(
{
"component": mo.ui.text(value=create_get_item_state(index, "component")("Onderdeel"), on_change=create_set_item_state(index, "component")),
"complexity": mo.ui.number(start=0, stop=1000, value=create_get_item_state(index, "complexity")(100), on_change=create_set_item_state(index, "complexity")),
"state": mo.ui.number(start=0, stop=10, value=create_get_item_state(index, "state")(8), on_change=create_set_item_state(index, "state")),
"influence": mo.ui.slider(start=0, stop=100, step=5, value=create_get_item_state(index, "influence")(50), on_change=create_set_item_state(index, "influence")),
}
)
return item

items = mo.ui.array([create_item(i) for i in range(num_items.value)])

mo.md(
"""
| Component | Complexity | State | Influence (in vs outside) |
| :- | -: | :- | :- |
"""
+ "\n".join(
[
f"""
| {item['component']}
| {item['complexity'].style({"width": "80px"})}
| {item['state'].style({"width": "80px"})}
| {item['influence']}
""".replace("\n", "")
for item in items
]
)
)
4 replies
Mmarimo
Created by dbunskoek on 4/10/2024 in #archived-help-and-support
Is there a way to create a syntax
yep, I thought so as well... I'm looking into that now, thanks!
9 replies
Mmarimo
Created by dbunskoek on 4/10/2024 in #archived-help-and-support
Is there a way to create a syntax
OK, thanks, I'll look into that! where should I create that feature-request? should it be a GitHub issue, and would it be helpful if I had a stab at an initial implementation myself?
9 replies
Mmarimo
Created by dbunskoek on 4/10/2024 in #archived-help-and-support
Is there a way to create a syntax
I'm currently looking at the source code for mo.md, and it looks like I could use a custom pymdownx extension for this
9 replies
Mmarimo
Created by dbunskoek on 4/10/2024 in #archived-help-and-support
Is there a way to create a syntax
could I perhaps override / extend the current mo.md function for that? or is there a better way?
9 replies
Mmarimo
Created by dbunskoek on 4/10/2024 in #archived-help-and-support
Is there a way to create a syntax
ah, that sounds like an easier approach, thanks! any pointers on how I would make that button in marimo?
9 replies
Mmarimo
Created by dbunskoek on 4/10/2024 in #archived-help-and-support
Is there a way to create a syntax
I'm currently leaning towards building this using the anywidget (https://docs.marimo.io/api/inputs/anywidget.html#marimo.ui.anywidget) approach, is that the right way to go?
9 replies