Dynamically add a group of textInput()

For work, I'm creating a Shiny App that allows the user to add information regarding a quiz question (a question, its possible answers, and an explanation) inside textInput.

What I want to do is to insert a button ("Add new question") possibly with actionButton that dynamically adds one additional question (= its group of textInput for the question, its possible answers, and its explanation).

This is the group of textInputs:

(Dummy example of a group of textInputs):


textInput("question", label = h3("Question"), value = "Enter Question"),
br(),
br(),
textInput("correct_answer", label = h5("Correct Answer"), value = "Enter Correct Answer"),
textInput("wrong_answer", label = h5("Wrong Answer"), value = "Enter Wrong Answer"),
br(), 
br(),
textInput("explanation", label = h3("Explanation"), value = "Enter Explanation"),
br(),
actionButton("add_new_question", "Add Another Quiz Question", class = "btn-primary"),

Please let me know if I should add in any other additional information!
Thanks,

I think it will be hard to answer this question directly, since there are multiple ways to implement dynamic UI in Shiny and only you know the full app context well enough to determine which is most appropriate for your case. If you haven't already seen it, I'd recommend starting with this article: https://shiny.rstudio.com/articles/dynamic-ui.html There are also some dynamic UI examples in the Shiny Gallery.

Once you've chosen your approach and given the code a try, I think from there it will be easier for people here to help you over any stumbling blocks.

1 Like