Building Web Applications with Shiny in R
Ramnath Vaidyanathan
VP of Product Research
ui <- bootstrapPage( theme = shinythemes::shinytheme('simplex'),
leaflet::leafletOutput('map', width = '100%', height = '100%'),
absolutePanel(top = 10, right = 10, id = 'controls',
sliderInput('nb_fatalities', 'Minimum Fatalities', 1, 40, 10),
dateRangeInput('date_range', 'Select Date', "2010-01-01", "2019-12-01"),
)
, tags$style(type = "text/css", " html, body {width:100%;height:100%} #controls{background-color:white;padding:20px;} ")
)
server <- function(input, output, session){
output$map <- leaflet::renderLeaflet({
leaflet() %>%
addTiles() %>%
setView( -98.58, 39.82, zoom = 5)
})
}
rval_mass_shootings <- reactive({
mass_shootings %>%
filter(
date >= input$date_range[1],
date <= input$date_range[2],
fatalities >= input$nb_fatalities
)
})
output$map <- leaflet::renderLeaflet({
rval_mass_shootings() %>%
leaflet() %>% addTiles() %>% setView( -98.58, 39.82, zoom = 5) %>%
addCircleMarkers(
popup = ~ summary,
radius = ~ fatalities,
fillColor = 'red', color = 'red', weight = 1
)
})
ui <- bootstrapPage( theme = shinythemes::shinytheme('simplex'), leaflet::leafletOutput('map', width = '100%', height = '100%'), absolutePanel(top = 10, right = 10, id = 'controls', sliderInput('nb_fatalities', 'Minimum Fatalities', 1, 40, 10), dateRangeInput('date_range', 'Select Date', "2010-01-01", "2019-12-01"),
actionButton('show_about', 'About')
) )
server <- function(input, output, session){
observeEvent(input$show_about, {
showModal(modalDialog(text_about, title = 'About'))
})
}
Building Web Applications with Shiny in R