I am designing an small annotation interface which will present users with a series of examples. An example will be presented to a user, they will make a mutually exclusive selection using a radio button, then more information will be presented in a second button where they can make a new selection with the same options; after submitting this, they move to the next example. I have the following code:
#!/usr/bin/env python3
import streamlit as st
columns = ["question", "answerA", "answerB", "answerC", "explanationA", "explanationB", "explanationC", "answer"]
with open('fake_data.tsv') as f:
examples = [dict(zip(columns, line.strip().split("\t"))) for line in f]
def show_example(examples, i, answers):
example = examples[i]
st.header("context: TODO, wire this up")
answer_before = st.radio(example["question"], [example["answerA"], example["answerB"], example["answerC"], "multiple options"], key=f"q1-{i}")
if st.button("submit", key=f"b1-{i}"):
answer_after = st.radio(example["question"], [
": ".join((example["answerA"], example["explanationA"])),
": ".join((example["answerB"], example["explanationB"])),
": ".join((example["answerC"], example["explanationC"])),
"multiple options"
], key=f"q2-{i}")
if i + 1 == len(examples):
print("Saving answers")
else:
if st.button("next question", key=f"b2-{i}"):
answers.append((answer_before, answer_after))
return show_example(examples, i+1, answers)
show_example(examples, 0, [])
which when run with a sample data file:
- Presents the first example's first part
- Allows a user to submit their answer
- Presents the first example's second part
but when a different selection is made in (3), the second radio button disappears completely.
My data file is here:
fake_data.tsv
:
question0 answerA0 answerB0 answerC0 explanationA0 explanationB0 explanationC0 acceptedAnswer0
question1 answerA1 answerB1 answerC1 explanationA1 explanationB1 explanationC1 acceptedAnswer1
question2 answerA2 answerB2 answerC2 explanationA2 explanationB2 explanationC2 acceptedAnswer2
question3 answerA3 answerB3 answerC3 explanationA3 explanationB3 explanationC3 acceptedAnswer3
How can I achieve my desired interaction? I'm using streamlit 1.22.0.
key
value. for the selection, that's the reason its acting strangely