Search code examples
rhighchartsshinyflexdashboardreact-highcharts

Input filter not working for reactive highchart


I've created an input slider that gives the user the option of selecting a hospital services from our dataset. I have a chart that shows the number of patients by age group. However, I want to be able to have this chart filter based on the service. Here is what I have so far, but it's not working.

library(flexdashboard)
library(highcharter)
library(DT)
library(dplyr)
library(shiny)

full_sql <- read.csv('clean.csv')
service_choice <- full_sql$Service


selectInput(inputId = "testsvc", 
            label = 'Services', service_choice)


ages_by_group <- full_sql %>%
        group_by(Pediatric.Patient.Age.Grouper) %>%
        summarise('Number of Patients' = n())

output$coolplot <- renderHighchart(
    hchart(
      ages_by_group  %>%
        filter('Service' >= input$testsvc), 
      type = "column", 
      hcaes(x = Pediatric.Patient.Age.Grouper, y = `Number of Patients`), 
      color = ocqi_colors("blue"), 
      dataLabels = list(enabled = TRUE)) %>%  
    hc_ocqi_opts() %>% 
    hc_add_theme(hc_theme_ocqi()) %>% 
    hc_title(text = list("Number of Patients by Age Groups"),
             align = "left") %>% 
    hc_credits(enabled = TRUE, text = "Data Source: CDW, Chart Type: Bar") %>%
    hc_yAxis(title = list(text = "Number of Patients")) %>% 
    hc_xAxis(title = list(text = "Age Group")) 
    )

Solution

  • You probably need -

    ages_by_group  %>%
      filter(Service %in% input$testsvc)