Created
March 21, 2016 08:00
-
-
Save loiyumba/54c6e347c681e73ee80d to your computer and use it in GitHub Desktop.
shinyapp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Shiny app for Hospital Directory | |
# Load the package | |
require(shiny) | |
# Data is cleaned and reloaded | |
hosp <- read.csv("cleaned2.csv", stringsAsFactors = FALSE) | |
# Define the overall UI | |
ui <- | |
fluidPage( | |
titlePanel("Hospital Directory"), | |
# Create a new Row in the UI for selectInputs | |
fluidRow( | |
column(2, | |
selectInput("state", | |
"State", | |
# c("All", | |
unique(as.character(hosp$State))) | |
), | |
column(2, | |
selectInput("district", | |
"District", | |
# c("All", | |
unique(as.character(hosp$District))) | |
) | |
), | |
# Create a new row for the table. | |
fluidRow( | |
h5(textOutput("footer")), | |
DT::dataTableOutput("table") | |
)) | |
# Server function | |
server <- function(input, output, session) { | |
# Filter data based on selections | |
output$table <- DT::renderDataTable(DT::datatable({ | |
data <- hosp | |
#if (input$state == "All") { | |
data <- data[data$State == input$state,] | |
#} | |
#if (input$district == "All") { | |
data <- data[data$District == input$district,] | |
#} | |
data | |
})) | |
observe({ | |
StateInput <- input$state | |
updateSelectInput(session, "district", choices = hosp$District[hosp$State == StateInput]) | |
}) | |
output$footer <- renderText({ | |
"Data Source: https://data.gov.in/" | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment