【发布时间】:2023-04-09 05:12:01
【问题描述】:
我正在构建一个带有多个选项卡的闪亮应用程序,每个选项卡都接受用户输入(唯一(data_in$cat),并生成某种类型的图形。问题出现在第二个选项卡中——出于某种原因,它没有生成由data2指定的图形。第一个选项卡上的第一个图形显示正确。运行此代码时我没有看到错误,所以我不知道从哪里开始调试!
library(shiny)
library(openxlsx)
library(ggplot2)
data_in <- read.xlsx("www/dem_data_clean.xlsx")
ui <- navbarPage(title = "Data",
tabPanel(title = "Over-all trends",
plotOutput("Histall"),
selectInput("Indall","Demographic Variable of Interest",choices = unique(data_in$cat))
),
tabPanel(title = "2017-2018"),
plotOutput("Hist17"),
selectInput("Ind17","Demographic Variable of Interest",choices = unique(data_in$cat))
)
server <- function(input, output, session) {
data1 <- reactive({
a <- subset(data_in,cat==input$Indall)
return(a)
})
data2 <- reactive({
a <- subset(data_in,cat==input$Ind17)
return(a)
})
output$Histall <- renderPlot({
ggplot(data1(), aes(x=Year,y=value, group =name, color=name)) + geom_line(stat = "identity") +
ylab("Percent of Population")
})
output$Hist17 <- renderPlot({
data2() %>%
filter(Year=="2017-18") %>%
ggplot(aes(name, value)) + geom_bar(stat = "identity")
})
}
shinyApp(ui, server)
对我做错了什么有什么建议吗?我已经尝试玩不同的东西几个小时了,但无济于事!
【问题讨论】:
-
看来
plotOutput("Hist17")和selectInput("Ind17", ...)在第二个tabPanel(title = "2017-2018")的括号之外。