0

Here is my UI, I am working on plot #2. The 3 choices that appear are columns (numeric) of df.

shinyApp(
  #####UI 
  ui = shinyUI(fluidPage(
    
    # Application title
    titlePanel(""),
    mainPanel(
      tabsetPanel(
        # Tab # 
        tabPanel("Map",
                 #plotlyOutput('mymap'),
                 selectInput("map_metric", "Choose a metric:", 
                             choices = c("Case.Count","Death.Due.to.Illness.Count","Hospitalized.Count"))),
        # Tab 2 -
        tabPanel("Responses Over Time", plotOutput("plot2"),
                 selectInput("county_2", "Choose a County", choices = unique(df$name)),
                 selectInput("response_2","Choose a Response:",
                             choices = c("Case.Count","Death.Due.to.Illness.Count","Hospitalized.Count")),
                 selectInput("cr_2","Select Counts or Rates:",
                             choices = c("Counts","Rates"))
                 )
      ) #tabset panel
    ) # mainpanel
  ) #FluidPage
)

Here is my server.

server = shinyServer(function(input, output) {
    
    df2 <-reactive ({
      df %>%
      dplyr::filter(name == input$county_2 ) %>%
      group_by(Onset.Date) %>% 
      summarize(n= sum(as.numeric(input$response_2))) %>%
      mutate(moving_average = rollmean(n,k=7,fill=NA))
    })
    
    output$plot2<- renderPlot({
        ggplot(df2(),aes(x=Onset.Date, y=n)) +
        geom_bar(stat="identity", fill ="#ccdddd")+
        theme(panel.background = element_blank(),axis.ticks = element_blank(),
              axis.title = element_blank(),
              axis.text.x = element_text(face = "bold",size = 11 ,angle = 90),
              axis.text.y = element_text(face = "bold",size = 12),
              legend.background = element_rect(fill = "black"),legend.key = element_rect(fill = "black"),
              legend.title = element_blank()) 
    })
      
  }) #shiny server
 
) #shiny app

I am not getting any errors but the plot just won't appear when I run the app! I replicated without a reactive function and it plotted fine. Its when I add the select inputs that it won't plot.

  • 1
    Hi @linacarrilo. In `summarize(n= sum(as.numeric(input$response_2)))` try with `summarize(n= sum(as.numeric(.data[[input$response_2]])))`. `input$response_2` is a string. Using `.data[[]]` will tell dplyr that this string is the name of a variable in your dataset. Otherwise the result is a `NA`. – stefan Nov 30 '20 at 19:34
  • You are a life saver! Thank you so much – linacarrillo Nov 30 '20 at 19:36

0 Answers0