Hi,
I am working on a Shiny app.
My ui.R
fluidPage(
titlePanel("Downloading Data"),
fluidRow(
column(3, wellPanel(
selectInput("input_type", "Choose chapter",
c( "Chapter 1" = "ch1",
"Chapter 2" = "ch2"
)
),
br(),
br(),
# This outputs the dynamic UI component
uiOutput("ui"),
# Button
downloadButton("downloadData", "Download")
)),
column(8,
DT::dataTableOutput("table")
)
)
)
When selecting input_type depending on item selected a radiobutton is shown. My server.ui:
## Data tab
output$ui <- renderUI({
if (is.null(input$input_type))
return()
# Depending on input$input_type, we'll generate a different
# UI component and send it to the client.
switch(input$input_type,
"ch1" = radioButtons("rb1", "Selection 1",
choices = c("Reason 1" = "db1",
"Reason 2" = "db2"),
selected = "db1"
),
"ch2" = radioButtons("rb2", "Selection 2",
choices = c("Answer 1" = "db3",
"Answer 2" = "db4"
)
})
# Reactive value for selected dataset ----
datasetInput <- reactive({
if (input$input_type == "ch1" & input$rb1 == "db1") {data <- db1}
else if (input$input_type == "ch1" & input$rb1 == "db2") {data <-db2}
else if (input$input_type == "ch2" & input$rb2 == "db3") {data <-db3}
else if (input$input_type == "ch2" & input$rb2== "db4") {data <-db4}
return(data)
})
# Table of selected dataset ----
output$table <- DT::renderDataTable(
datasetInput(), options = list(
lengthChange = FALSE,
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#42f', 'color': '#fff'});",
"}"))
)
So selectInput activates different radiobuttons rb1 and rb2. Based on selection on this radiobuttons different dbs are shown.
App works but some error is thrown:
Warning: Error in if: argument is of length zero
119: reactive:datasetInput
What is going wrong?
Thx