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?
library(shiny)
hospitals <- read.csv("data/hospitals.csv")
ui <- fluidPage(
tabPanel("Distance from Hospital", p(), sidebarLayout( sidebarPanel( selectInput(inputId ="selected.state", label = "Choose a State", hospitals$State, selected = TRUE) actionButton(inputId = "update", label = "Update")
mainPanel(
tableOutput('filtered_table')
)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() })
}