– Rshiny Module Issue: Unable to access input values of innerModuleUI from innerModuleServer

Hi all,

I am new to Rshiny modules and have been having a bit of a hard time getting my head around them.

Essentially I am trying to make a nested module where the inner module is dynamically generated.

The outer module has an action button. When pressed it inserts an set of selectors (innerUI). The button can be pressed multiple times such that the innerUI is inserted multiple times.

In each set of the innerUI elements, two of the inputs are used to generate the choices of the other two.

I have tried to do this with an innerServer module that uses observeEvents to try and do this. However, the inner module seems to be unable to access the values of the inputs. For instance, if I print(input$creditLevelSelector) in the innerSever code it will return NULL, despite being populated in app and being the column names of the data by default.

Any idea why the innerServer is not working as expected?



#UI elements
specificTransactionOuterUI<-function(id,data){
  useShinyjs()

  ns <- NS(id)
 
  tagList(
  actionButton(inputId=ns("createSpecificFlow"), "Add New Specific Transaction Column"),

  uiOutput(ns("specificTransactionUI"))
  )
}




#####sever code inner UI

specificTransactionInnerUiTemplate<-function(id, data){
  useShinyjs()
  ns=NS(id)
 
  div(id =ns("specifcTransactionInnerUiDiv"),
 
    fluidRow(
     
      column(4,
             
             
             
             textInput("newColSpecificTransaction", "Give new column a name", value = ""),
             br(),
             
             pickerInput(  inputId=ns("creditLevelSelector"),
                           label = "Select level",
                           choices=colnames(data),
                           selected = NULL,
                           multiple = FALSE
                           
             ),
             br(),
             
             pickerInput(  inputId=ns("debitLevelSelector"),
                           label = "Select Level",
                           choices= colnames(data),
                           selected = NULL,
                           multiple = FALSE
             )
             
      ),
     
     
      column(4,
             br(),
             br(),br(),
             br(),
             pickerInput(  inputId=ns("creditValues"),
                           label = "Select credit side",
                           choices=NULL,
                           selected = NULL,
                           multiple = TRUE,
                           options = pickerOptions(
                             actionsBox = TRUE,
                             selectedTextFormat = "count",
                             liveSearch = TRUE
                           )
             ),
             
             br(),
             
             pickerInput(  inputId=ns("debitValues"),
                           label = "Select debit side",
                           choices=NULL,
                           selected = NULL,
                           multiple = TRUE,
                           options = pickerOptions(
                             actionsBox = TRUE,
                             selectedTextFormat = "count",
                             liveSearch = TRUE
                           )
             )
             
      ),
     
     
     
      column(4,
             br(),br(),
             br(),br(),br(),br(),
             actionButton( inputId=ns("RemoveSpecificTransaction"), "Remove Specific Flow Column")
             
      )
     
    )
 
 
 
  )
  }
 
#updates
specificTransactionInnerServer<-function(id,data){
  moduleServer(
    id,
    function(input, output, session) {


      ns <- session$ns
  #

observeEvent(input$creditLevelSelector,{
 


  updatePickerInput(
    session,
    inputId="creditValues",
   choices = unique(data[[input$creditLevelSelector]])

     )
})

#updateValuesDebits

observeEvent(input$debitLevelSelector,{


  updatePickerInput(
    session,
    inputId="debitValues",
    choices = unique(data[[input$debitLevelSelector]])

  )


})

# ###remove button server side

observeEvent(input$RemoveSpecificTransaction, {

  removeUI(selector =paste0("#", ns("specifcTransactionInnerUiDiv")))
  remove_shiny_inputs(id, input)

})



    }
)
}
 




##########server code - outer UI

specificTransactionOuterServer<-  function(id,data){
  moduleServer(
    id,
  function(input, output, session) {
 
   
     counter<-reactiveValues()

     counter$count=0
     
     ns <-session$ns
     
     
   
   
     observeEvent(input$createSpecificFlow, {
         
         counter$count=counter$count+1
        insertUI(selector=paste0("#",ns("specificTransactionUI")),where="afterEnd", specificTransactionInnerUiTemplate(id=paste0("specificFlow", counter$count ), data) )
        specificTransactionInnerServer(id=paste0("specificFlow", counter$count ), data)
         
         
         
     }
     
   
)
       


  }

)
}





This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.