library(shiny)
testInput <- function(id) {
ns <- NS(id)
tagList(
selectInput(inputId = ns("input1"), label = "Updater", choices = c("Value A", "Value B")),
hr(),
radioButtons(inputId = ns("input2"), label = "Radio Buttons", choices = c("Value AA", "Value AB")),
selectInput(inputId = ns("input3"), label = "Select Input", choices = c("Value AA", "Value AB")),
textInput(inputId = ns("input4"), label = "Text Input", value = "Value AA"),
checkboxGroupInput(inputId = ns("input5"), label = "Checkbox Group", choices = c("Value AA", "Value AB")),
radioButtons(inputId = ns("input6"), label = "Radio Buttons (No Update)", choices = c("Value AA", "Value AB")),
checkboxGroupInput(inputId = ns("input7"), label = "Checkbox Group (No Update)", choices = c("Value AA", "Value AB"))
)
}
testModule <- function(input, output, session) {
observeEvent(input$input1, {
ns <- session$ns
if (input$input1 == "Value A") {
values <- c("Value AA", "Value AB")
} else {
values <- c("Value BA", "Value BB")
}
updateRadioButtons(session = session, inputId = "input2", label = "Radio Buttons", choices = values)
updateSelectInput(session = session, inputId = "input3", label = "Select Input", choices = values)
updateTextInput(session = session, inputId = "input4", label = "Text Input", value = values[1])
updateCheckboxGroupInput(session = session, inputId = "input5", label = "Checkbox Group", choices = values)
})
dataframe <- reactive({
data.frame(radioButton = input$input2,
radioButton_no_update = input$input6,
SelectInput=input$input3,
TextInput=input$input4,
Checkboxes=paste0(input$input5, collapse = ", "),
checkBox_no_update = paste0(input$input7, collapse = ", "),
value = rnorm(1))
})
return(dataframe)
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
testInput("test")
),
mainPanel(
dataTableOutput("table")
)
)
)
server <- function(input, output, session) {
exampledata <- callModule(testModule, "test")
output$table <- renderDataTable({
exampledata()
})
}
shinyApp(ui, server)