【问题标题】:Allow empty value "" as choice in selectInput允许空值“”作为 selectInput 中的选项
【发布时间】:2020-09-27 11:27:19
【问题描述】:

我正在开发一个闪亮的应用程序,它有一个 selectInput 过滤器,它的选择来自 NAMES 的数据框。此 selectinput 允许根据名称过滤 rhandsontable 中的行。 目前 selectinput 不显示“”选项,其中 NAME 为空,即“”,只显示可用的名称。 我想通过 selectinput 过滤表中没有任何名称(即 NAMES=="")的行。 你能帮忙看看怎么做吗?

【问题讨论】:

    标签: r shiny selectinput


    【解决方案1】:

    我建议您使用shinyWidgets 套餐,我知道selectInput 不允许您进行null 表演:

    library(shiny)
    library(shinyWidgets)
    
    data <- head(mtcars)
    data$NAMES <- data$mpg
    data$NAMES[c(1,3)] <- ""
    
    ui <- fluidPage(
        pickerInput(
            inputId = "NAMES",
            label = "NAMES", 
            choices = unique(data$NAMES),
            selected = "",
            multiple = TRUE,
            options = pickerOptions(maxOptions = 1)
        ),
        tableOutput("table")
    )
    server <- function(input, output,session) {
    
        mydata <- eventReactive(input$NAMES,{
            data[data$NAMES %in% input$NAMES,]
        })
    
    
        output$table <- renderTable({
            mydata()
        })
    
    }
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

    • 谢谢!这很完美。我还有一个障碍,如果没有选择任何过滤器,我有一个检查“isTruthy”以显示所有数据,因为我有多个过滤器。“”值没有通过这个检查。有什么你知道的解决方法,真的很有帮助。
    猜你喜欢
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2019-06-21
    • 2023-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多