简体   繁体   中英

selectInput does not show default value

The selectInput is set with default value = "Y", but in the server stage, input$featureselection == NULL. The sample code is as follows:

ui <- pageWithSidebar(

               selectInput(
                  inputId = "featureselection", "Featureselection step:",
                  c("Yes" = "Y",
                    "No" = "N"),
                  selected = "Y") # have tried selected = "Y" or "Yes" 
                ,fileInput(
                  inputId = "input_featuredata",
                  "Upload feature data. Choose rds file",
                  accept = c(".csv",".rds")
                )
                ,fileInput(
                  inputId = "input_classdata",
                  "Upload class data. Choose rds file",
                  accept = c(".csv",".rds")
                )
                ,shinyjs::useShinyjs()
                ,shinyjs::hidden(
                  fileInput(
                  inputId = "input_effectsize",
                  "Upload a vector of effect size",
                  accept = c(".csv",".rds")
                )
                ,numericInput(
                  inputId = "input_classprob",
                  "Probability of incidence",
                  value = 0.5, min = 0, max = 1
                )
                ,numericInput(
                  inputId = "input_totalnum",
                  "Total number of features",
                  value = 0.5, min = 0, max = 1
                )
                
                )
)
server <- function(input, output) {
  observe({
  fstep <- input$featureselection
  fstep
  
  if (fstep == "N"){
      shinyjs::hide(id = "input_featuredata")
      shinyjs::hide(id = "input_classdata")
      shinyjs::show(id = "input_effectsize")
      shinyjs::show(id = "input_classprob")
      shinyjs::show(id = "input_p")
  }
})
}


The default value for the selectInput should be "Y", but the input$featureselection still shows NULL ( fstep == NULL ) when the program operates.

Did I set things correctly?

I still cannot force selectInput to show default value, so I change the server part to be:

observe({
  if (!is.null(input$featureselection)){
    if (input$featureselection == "No"){
          shinyjs::hide(id = "input_featuredata")
          shinyjs::hide(id = "input_classdata")
          shinyjs::show(id = "input_effectsize")
          shinyjs::show(id = "input_classprob")
          shinyjs::show(id = "input_totalnum")
    }
    
    if (input$featureselection == "Yes"){
      shinyjs::show(id = "input_featuredata")
      shinyjs::show(id = "input_classdata")
      shinyjs::hide(id = "input_effectsize")
      shinyjs::hide(id = "input_classprob")
      shinyjs::hide(id = "input_totalnum")
    }
  }

})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM