【发布时间】:2020-11-08 11:38:25
【问题描述】:
我正在构建一个 shinyApp 来显示 COVID-19 数据。我有一个长格式的文件,显示日期、县、阳性病例、康复和死亡人数。我正在尝试制作用户可以从下拉菜单中选择一个县的应用程序,它将在页面上显示 3 个阳性、恢复和死亡图表。这些图表将 x 轴作为日期,将 y 轴作为变量。附件是我到目前为止的脚本。我尝试了许多不同的方法,但我不知道该怎么做。我仍在学习 R,之前没有使用 ShinyApp 的经验。任何建议或帮助将不胜感激。我想我的 ggPlot 和输出/UI 是正确的,服务器逻辑是让我陷入循环的原因。即使只是一个好的指南的链接也会很好。谢谢!
2020 年 7 月 23 日:我已更新代码。我在ggplot中看了一些。当我运行应用程序时,我现在有了我想要的下拉菜单,但图表正在显示。当我在控制台中创建 ggplot 以确保代码自行运行时,我错过了图表的中间部分?有什么想法/修复吗?
library(shiny)
library(dplyr)
library(tidyr)
library(plotly)
library(ggplot2)
library(rsconnect)
df <- read.csv("C:/Users/Nathan May/Desktop/Research Files (ABI)/Covid/Data For Shiny/Appended_File/Appended_Scraped_Files.csv") #INSERT PATH SINGLE FILE OPTION
datapos <- df[c(2,6,3)]
rsconnect::setAccountInfo(name='nathanjmay', token='A3CF4CC3DE0112B8B9F8D0BA429223D3', secret='TNwC9hxwZt+BffOhFaXD3FQsMg3eQnfaPGr0eE8S')
#UI
ui <- fluidPage(
titlePanel("COVID-19 in Arkansas Counties"),
fluidRow(
column(
width=4,
selectizeInput("County", label=h5("County"), choices= data$Counties, width="100%")
)),
fluidRow(
plotOutput(outputId = "Positive")
),
fluidRow(
plotOutput(outputId = "Recoveries")
),
fluidRow(
plotOutput(outputId = "Deaths")
),)
#SERVER
server= function(input, output) {
data <- reactive({
datapos %>% filter(County == input$County)
#GGPLOT2 for Positive
output$Positive -> renderPlot(ggplot(data=datapos, aes(x=Day, y=Positive)) +
geom_bar(stat="identity"))
#Recoveries
output$Recoveries -> renderplot()
#Deaths
output$Deaths -> renderplot()
})
}
shinyApp(ui=ui, server=server)
【问题讨论】:
-
服务器内部可能需要
datapos %>% filter(County == input$County),而ggplotP不是大写的 -
@akrun 你的建议奏效了!现在,如果我能让它显示图表就好了。如果您有任何想法,我已经更新了上述问题中的代码?我在应用程序启动时也收到以下错误:data$Counties 中的错误:'closure' 类型的对象不是子集