繁体   English   中英

在 Shiny 中过滤反应式表

[英]Filtering a Reactive table in Shiny

在我的数据框“df”中,我有一个名为“currentABC”的列,它有几个唯一的字符类型值。 在我的闪亮模型中,我想使其在侧边栏面板中可以选择这些唯一值之一,并且在我的反应表中,只有“currentABC”与所选输入值匹配的行显示在表中。 下面不是我的所有代码,而是我认为问题所在的一个片段。 目前我收到一条错误消息,上面写着

“在为函数 'filter' 选择方法时评估参数 'condition' 时出错:在为函数 '%in%' 选择方法时评估参数 'x' 时出错:找不到对象 'currentVOI'”

谢谢!

ui <- fluidPage(
  titlePanel("title"),
  sidebarLayout(
    sidebarPanel(
      selectInput(inputId = "CurrentABC",  
      label = "1. Select ABC",  
      choices = unique(df$currentVOI), selected = "123"), 





 server <- function(input, output, session) { 

table <- reactive({
  df %>% filter(currentABC == input$CurrentABC)
})
                                   
                                   
output$mytable <- renderTable({
  table()
})
 
                                   
} 

这是 iris 数据集的示例,您可以如何做到这一点:在服务器部分,您可以测试两个选项(第一个被注释掉)来测试只需注释掉服务器部分中的其他代码:

library(shiny)
library(dplyr)

# Define UI
ui <- fluidPage(
  # Application title
  titlePanel("Filter by Species"),
  
  sidebarLayout(# Sidebar with a slider input
    sidebarPanel(
      selectInput("species", "Species",
                  choices = levels(iris$Species)
                  )
      ),
      
      # Show a plot of the generated distribution
      mainPanel(tableOutput("my_table")
                )
    )
  )

server <- function(input, output) {
  
  # output$my_table <- renderTable({
  #   subset(iris, Species == input$species)
  # })
  
  table <- reactive({
    iris %>% 
      filter(Species == input$species)
  })
  
  output$my_table <- renderTable({
    table()
  })
  
}

shinyApp(ui, server)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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