Trying to dynamically create a list of questions in Shiny


#1

I am trying to create a list of questions that are displayed based on the category and the number of questions.

I have found a way to create the question list using lapply and modules, but it does not behave as expected.

I cannot select a radio button. When I do, it resets all the buttons and does not record an answer. I cannot figure out what the issue is.

Please help with either a diagnosis or an alternative means of doing this.

The necessary files are located on GitHub.


#2

So my question has changed. After much trial and mostly error, I can now generate the list of radio buttons correctly, and they do not reset when one is selected.

Now how do I access the selections made? The module based name space is not accessible outside the module so the dynamically generated namespace ID’s for each radioButton cannot be accessed usng input$ID. This appears to work differently because of the use of modules.

The code in my example on Github has been updated to my latest. (See the Github link above)


#3

Modules can return reactive objects which are then accessible in the "master". As a minimal example:

mod_server = function(input,output,session){
  autoInvalidate = reactiveTimer(1000)
  rv = reactiveValues(x = NULL)
  observeEvent(autoInvalidate(),{
    # update the reactive value x every second with random value
      rv$x = runif(1)
    }
  )
  return(rv)
}

ui = fluidPage(textOutput("out"))
server = function(input,output,session){
  # binding for returned reactivevalues from module
  modulevalue = callModule(mod_server,"id")
  # x is the object in the reactivevalues that contains the random number
  output$out = renderText(modulevalue$x)
}

shinyApp(ui,server)