我的闪亮UI和服务器代码如下:
shinyUI(navbarPage("Data Dashboard",
tabPanel("Education"),
navbarMenu("Healthcare",
tabPanel("Insurance",
sidebarPanel(
selectInput("variable", "Factor: ",
list("Uninsured %" = "uninsured",
"Primary Care Physicians" = "primary_care_physicians",
"Mental Health Providers" = "mental_health_providers",
"Dentists" = "dentists"
))
),
mainPanel(
plotOutput("yearPlot"))),
tabPanel("Metrics",
sidebarPanel(
selectInput("variable", "Metric: ",
list("Adult Obesity" = "adult_obesity",
"Adult Smoking" = "adult_smoking",
"Accident Deaths" = "motor_vehicle_crash_deaths",
"Physical Inactivity" = "physical_inactivity",
"Alcoholism" = "excessive_drinking",
"Diabetes" = "diabetes"
))
),
mainPanel(
plotOutput("metPlot")))),
navbarMenu("More",
tabPanel("Sub-Component A"),
tabPanel("Sub-Component B"))
))
shinyServer(function(input, output) {
#Healthcare: Insurance
output$yearPlot <- renderPlot({
df <- data.frame(year=as.factor(insurance$year), County = as.factor(insurance$County), variable = insurance[[input$variable]])
ggplot(df, aes_string(df$year, y=df$variable, fill = df$County)) + geom_bar(stat = "Identity") + facet_wrap(~df$County)
})
#Healthcare: Metrics
output$metPlot <- renderPlot({
df2 <- data.frame(year=as.factor(healthdata$year), County = as.factor(healthdata$County), variable = healthdata[[input$variable]])
ggplot(df2, aes_string(df2$year, y=df2$variable, fill = df2$County)) + geom_bar(stat = "Identity") + facet_wrap(~df2$County)
})
})
我不断收到错误消息:data.frame: arguments imply differing number of rows: 15, 0.
中的错误,我想知道是否应该为ShinyServer函数添加一个单独的输入参数,但是对于为什么会发生这种情况我有些困惑。
我的数据: