【发布时间】:2020-07-24 03:36:53
【问题描述】:
我正在尝试构建一个 Corona 仪表板。如果有人从下拉列表中选择州,则将在图表中显示地区案例。例如。如果有人选择古吉拉特邦,它会在条形图中显示地区案例。有人将其更改为马哈拉施特拉邦,它应该随着马哈拉施特拉邦的地区而更新。
但我得到 “ERROR:data must be a data frame, or other object coercible by fortify(), not an S3 object with class reactiveExpr/reactive”错误。
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)
【问题讨论】:
标签: r shiny shinydashboard