尝试应用条件过滤器时出错

Errors when trying to apply conditional filters

我有以下数据,我正在尝试为其制作一组下拉过滤器,这些过滤器将根据过滤器中 selected 的内容更改显示的数据框:

myData<- structure(list(waterbody = c("Homer", "Homer", "Homer", "Homer", 
"West", "West", "West", "East", "East", "East", "East", "Walnut", 
"Walnut", "Walnut", "Walnut"), transect_number = c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), species = c("LMB", 
"LMB", "GZS", "BLG", "LMB", "GZS", "BLG", "BLG", "BLG", "GZS", 
"BLG", "BLG", "LMB", "GZS", "LMB"), length_mm = c(430L, 430L, 
NA, 165L, 345L, NA, 128L, 117L, 93L, NA, 135L, 161L, 402L, NA, 
347L), wt_g = c(1270L, 1325L, NA, 108L, 545L, NA, 40L, 28L, 15L, 
NA, 42L, 81L, 865L, NA, 525L)), row.names = c(NA, -15L), class = "data.frame")

此外,每个后续过滤器中的选项都应根据前一个 selected 的内容而变化。因此 select 可用的物种会根据 select 的水体而变化(因为并非所有水体都出现在每个水中)。

到目前为止我的代码:

# User Interface
ui <- shinyUI(
  fluidPage(
    titlePanel("File Inputs"),
    sidebarLayout(
      sidebarPanel(
        fileInput(
          'data',
          'Choose CSV File',
          accept = c('text/csv',
                     'text/comma-separated-values,text/plain',
                     '.csv')
        ),
        uiOutput("pick_waterbody"),
        uiOutput("pick_species")
      ),
      mainPanel(DT::dataTableOutput('dt_table'),)
    )
  )
)
  
  
  
# Server
server <- function(input, output, session) {
    myData <- reactive({
      inFile <- input$data
      if (is.null(inFile))
        return(NULL)
      data <- read.csv(inFile$datapath, header = T)
      data
    })
    
    output$dt_table <- DT::renderDataTable({
      DT::datatable(myData())
    })

    
    output$pick_waterbody <- rednderUI({
      pickerInput(
        "pick_waterbody",
        "Water(s) of Interest:",
        choices = unique(myData$waterbody),
        options = list(`actions-box` = TRUE),
      )}
    )
    
    output$pick_species <- renderUI({
      updatePickerInput(
        "pick_species",
        "Species of Interest:",
        choices = as.character(myData[myData$waterbody == input$pick_waterbody, "species"]),
        options = list(`actions-box` = TRUE))
    })
}

output$dt_table 之后关闭服务器代码时,应用程序运行正常。但是,当我包含 output$pick_waterbody 代码时,出现“找不到函数 renderUI”错误。此外,output$pick_species 代码表示发现了意外的符号。我已经梳理了1000遍了,我似乎无法弄清楚这些问题。

非常感谢您帮助我找出问题所在。

您打错字了,需要 req(),而不是 updatePickerInput(),只是 pickerInput。试试这个

 output$pick_waterbody <- renderUI({
    req(myData())
    pickerInput(
      "pick_waterbody",
      "Water(s) of Interest:",
      choices = unique(myData()$waterbody),
      options = list(`actions-box` = TRUE),
    )}
  )
  
  output$pick_species <- renderUI({
    req(myData(),input$pick_waterbody)
    pickerInput(
      "pick_species",
      "Species of Interest:",
      choices = as.character(myData()[myData()$waterbody == input$pick_waterbody, "species"]),
      options = list(`actions-box` = TRUE))
  })