Problem of communication in nested modules

Hi

I have an issue with nested modules. I read various post on nested modules, the Rstudio blog on modules communications (https://shiny.rstudio.com/articles/communicate-bet-modules.html), and some other sources, but nothing seems to address my issue.

The code posted in https://gist.github.com/tbadams45/38f1f56e0f2d7ced3507ef11b0a2fdce was modified to illustrate my issue: I essentially need UI components from the inner module to depend on the selection of the outer module. The code posted below returns error message because input$outslider appears to be NULL (actually the whole input object appears empty). If I just replace the if else construct by alpha = 1, the app runs (but obviously does do why I need it to do.

I am not quite sure why the input object in the innerMod appears empty... so I would welcome any input.

Thanks in advance

 library(shiny)

innerMod <- function(input, output, session, n) {
 
  output$inner_slider <- renderUI({
   
    if (input$outslider < 5){
      alpha <- (n-1)*10 + 1
    } else {
      alpha <- (n-1)*100 + 1
    }
    sliderInput(
      session$ns("inslider"),
      label = paste("inner slider", n),
      min = 1*alpha,
      max = 10*alpha,
      value = 5*alpha,
      step = 1*alpha
    )
  })
}

outerMod <- function(input, output, session) {
  callModule(innerMod, "inner1", n = 1)
  callModule(innerMod, "inner2", n = 2)
}

innerModUI <- function(id) {
  ns <- NS(id)
 
  fluidPage(fluidRow(
    uiOutput(ns("inner_slider"))
  ))
}

outerModUI <- function(id) {
  ns <- NS(id)
  fluidPage(fluidRow(
    uiOutput("outer_slider"),
    innerModUI(ns("inner1")),
    innerModUI(ns("inner2"))
  ))
}

ui <- fluidPage(
  fluidRow(
    outerModUI("outer")
  )
)

server <- function(input, output, session) {
  callModule(outerMod, "outer")
 
  output$outer_slider <- renderUI({
    sliderInput(
      "outslider",
      label = "outer slider",
      min = 1,
      max = 10,
      value = 5,
      step = 1
    )
  })
 
}

shinyApp(ui = ui, server = server)

I am currently trying to store reactive data in session$userData which should be available to all the modules all the time but with mixed results so far. Maybe that helps. I can't help you directly because i am new to shiny.

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