首页 > 解决方案 > 按变量过滤数据帧并输出为闪亮的表格

问题描述

我对 Shiny 输出有点卡住了。我想过滤数据框并将结果输出为表格。数据框是案例的长格式。“变量”是我要过滤的区域:

> str(UZ_COVID19_long_rev0)
'data.frame':   1694 obs. of  3 variables:
 $ Date    : POSIXct, format: "2020-03-15" "2020-03-16" "2020-03-17" ...
 $ variable: Factor w/ 14 levels "Karak_Rep","Andijon",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ value   : num  0 0 0 0 0 0 0 0 0 0 ...


library(shiny)

tib<-UZ_COVID19_long_rev0

ui = pageWithSidebar(
    headerPanel("Selection Panel"),
    sidebarPanel(
        selectizeInput('region', 'Select region', 
                       choices = c(levels(tib$variable)))
    ),
    
    mainPanel(
        verbatimTextOutput("table")
    )
)

server = function(input, output, session) 
    {
    
    output$table <- renderTable({
        tib %>%
            filter(variable == input$region)
    })
        
    }
    
shinyApp(ui = ui, server = server)

但我收到一个错误:“找不到对象‘变量’”

我相信代码中存在错误,但无法获取。

标签: rdataframeshinyfiltering

解决方案


推荐阅读