ERROR:`data`必须是数据帧或其他可由fortify()强制执行的对象,而不是类别为activeExpr / reactive的S3对象

问题描述 投票:0回答:1

我正在尝试构建电晕仪表板。如果某人从下拉列表中选择州,则将在图中显示地区明智的案例。例如。如果有人选择古吉拉特邦,则会在条形图中显示区域明智案例。有人将其更改为马哈拉施特拉邦,它应该随着马哈拉施特拉邦地区进行更新。但是我得到了[[“错误:data必须是数据帧,或者是可由fortify()强制执行的其他对象,而不是具有类reactExpr / reactive的S3对象)”“错误。

library(shiny) library(readxl) library(ggplot2) library(dplyr) ui <- fluidPage( # Application title titlePanel("Corona Data"), # Sidebar with a slider input for number of bins sidebarLayout( sidebarPanel( selectInput(inputId = "state", label = "Select the State", choices = unique(data$`Detected State`)) ), # Show a plot of the generated distribution mainPanel( plotOutput("stateplot") ) ) ) data <- read_excel("Live Data Worldometer.xlsx", sheet = "IndiaData") data <- data[,c(-2,-1)] server <- function(session, input, output) { d1 <- reactive({data %>% group_by(`Detected State`) %>% count(`Detected District`) %>% filter(`Detected State` == input$state) }) output$stateplot <- renderPlot({ ggplot(d1, aes(d1$`Detected District`, d1$n))+geom_bar(stat = "identity") }) } # Run the application shinyApp(ui = ui, server = server)
This is the output I am getting
r shiny rstudio shinydashboard shiny-reactivity
1个回答
0
投票
[d1不是数据帧,而是需要求值的表达式。

server <- function(session, input, output) { d1 <- reactive({data %>% group_by(`Detected State`) %>% count(`Detected District`) %>% filter(`Detected State` == input$state) }) data <- d1() output$stateplot <- renderPlot({ ggplot(data, aes(`Detected District`, n))+geom_bar(stat = "identity") }) }

© www.soinside.com 2019 - 2024. All rights reserved.