Roman
Roman11mo ago

ui.dictionary

I'd like to use Marimo for literate DevOps. Let's say I want to share a collection of notebooks with my team and let's say we currently don't have a secrets storage. I'd like to have a bootstrap notebook which would check that the user has an encrypted YAML file with API keys and prompt for missing values. What's the best way to do that? My initial idea was to collect a list of missing entries and generate an ui.dictionary based on that but it looks like I can't pass a dictionary as value.
2 Replies
Akshay
Akshay11mo ago
Your initial idea is on the right track. Here's an example: https://static.marimo.app/static/mo-ui-dictionary-83qy Notebook code:
import marimo

__generated_with = "0.1.76"
app = marimo.App()


@app.cell
def __():
import marimo as mo
return mo,


@app.cell
def __():
missing_entries = [
"a",
"b",
"c"
]
return missing_entries,


@app.cell
def __(missing_entries, mo):
form = mo.ui.dictionary(
{key: mo.ui.text() for key in missing_entries},
label="enter these API keys",
).form()
form
return form,


@app.cell
def __(form):
form.value
return


if __name__ == "__main__":
app.run()
import marimo

__generated_with = "0.1.76"
app = marimo.App()


@app.cell
def __():
import marimo as mo
return mo,


@app.cell
def __():
missing_entries = [
"a",
"b",
"c"
]
return missing_entries,


@app.cell
def __(missing_entries, mo):
form = mo.ui.dictionary(
{key: mo.ui.text() for key in missing_entries},
label="enter these API keys",
).form()
form
return form,


@app.cell
def __(form):
form.value
return


if __name__ == "__main__":
app.run()
Let me know if this works for you?
Roman
RomanOP11mo ago
Oh. That should work, by the looks of it. I was thinking about map or something, but I wouldn't come up with something that smart! I'll test it now, thank you so much! Yes, it works, that's exactly what I was thinking of, an easy way to validate things! Didn't realize you can use constructors like that. This will help me maintain the collection: if I need another secret or constant, I just declare it's required in the bootstrap notebook, and it will give me a form to add it, similar to ansible vault but with less hassle.