0

My Shiny UI and Server code looks like:

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)
  })

})

I keep getting the error: Error in data.frame: arguments imply differing number of rows: 15, 0. I was wondering if I should add a separate input parameter to the shinyServer function but I'm a little confused as to why this is happening.

My data:

enter image description here

as26
  • 81
  • 8
  • It's hard to say without being able to see any of your data, but [see this](https://stackoverflow.com/q/32543340/5325862) R-FAQ post on why you basically never use `$` inside `aes` – camille Nov 02 '18 at 19:57
  • Edited the question to add a snapshot of the data – as26 Nov 02 '18 at 20:22
  • See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on posting an R question that is easy to answer. We can't work with your data from a picture of it – camille Nov 02 '18 at 20:46
  • well, too bad. thanks anyway – as26 Nov 02 '18 at 20:59
  • Huh? Look at the post I linked to. It lists ways to make your data reproducible – camille Nov 02 '18 at 21:01
  • `structure(list(year = c(2016L, 2015L, 2017L, 2017L, 2016L, 2015L ), uninsured = c(0.156, 0.158, 0.139, 0.124, 0.148, 0.152), primary_care_physicians = c(52, 48, 53, 62, 61, 61), mental_health_providers = c(153, 146, 165, 175, 171, 161), dentists = c(49, 48, 47, 60, 60, 60), County = c("Bronx County, NY", "Bronx County, NY", "Bronx County, NY", "Kings County, NY", "Kings County, NY", "Kings County, NY")), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"))` Sorry, does this help? – as26 Nov 02 '18 at 21:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/183032/discussion-between-as26-and-camille). – as26 Nov 02 '18 at 21:21

0 Answers0