Shiny: Filtering and displaying Dataframe from a eventReactive Input

I have the following codes.
I am trying to filter my dataset, based on the selected used input.
When user clicks update, I want to create a new dataset based on the filtered values.
I am unable to filter and show the output. Would anyone be able to help?


hospitals <- read.csv("data/hospitals.csv")

ui <- fluidPage(

tabPanel("Distance from Hospital", p(),

             selectInput(inputId ="selected.state", label = "Choose a State", hospitals$State, selected = TRUE)
             actionButton(inputId = "update", label = "Update")


server <- function(input, output) {

filtered_by_state <- eventReactive(input$update, {
data.frame(subset(ED_hospitals, State == input$selected.state))
output$filtered_table <- renderDataTable({ filtered_by_state() })

Hi @squeeks2117 and welcome:)
I am not able to run your code on my computer. See this post on how to create a reproducable example

Apart from that, what is the error you are getting? Did you define the variable ED_hospitals?

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.