1

I'm working on a Shiny app using the Golem framework, and I'm facing a challenge related to inter-module communication. Specifically, I have two modules: module1 contains a dropdown allowing users to select a country, and module2 is responsible for displaying UI elements based on the selected country of module1.

I want to conditionally show a numericInput element in module2 when the user selects 'France' in the dropdown of module1. Here's a simplified version of my code:

library(shiny)
library(golem)
library(shinyWidgets)

mod_module1_ui <- function(id){
  ns <- NS(id)
  tagList(
    shiny::inputPanel(
      shinyWidgets::awesomeRadio(
        inputId = ns("id_country"),
        label = 'Select the country:',
        choices =c('Spain','France',  'England')
      )  
    )
  )
}

# Server modulo1
mod_module1_server <- function(id){
  moduleServer( id, function(input, output, session){
    ns <- session$ns
    
  })
}

# User Interface modulo2
mod_module2_ui <- function(id){
  ns <- NS(id)
  tagList(
    shinydashboard::box(
      conditionalPanel(
        # this is where I try to access the value of the input from 'module1'
        condition = "input.module1_1-id_country == 'France'",
        ns = ns,
        numericInput(
          inputId = ns("year"),
          label = "Input Year:",
          value = 2017,
        )
      ) 
    )
  )
}

# Server modulo2
mod_module2_server <- function(id){
  moduleServer( id, function(input, output, session){
    ns <- session$ns
    
    # do something
    
  })
}

# APP User Interface
app_ui <- function(request) {
  tagList(
    mod_module1_ui("module1_1"),
    mod_module2_ui("module2_1") 
  )
}

app_server <- function(input, output, session) {
  mod_module1_server("module1_1")
  mod_module2_server("module2_1") 
}

shinyApp(app_ui,app_server)

I've tried the approach above using javascript language, but I'm struggling to make it work within the Golem structure. Could someone guide me on how to effectively pass the selected country value from module1 to module2 and conditionally display the numericInput element based on the country selection? Any help or example code demonstrating the correct way to achieve this would be greatly appreciated!

0 Answers0