StatisticsNZ / simplevis

Simple visualisation with ggplot2 and leaflet wrappers
https://StatisticsNZ.github.io/simplevis
Other
86 stars 11 forks source link

documentation: in shiny article, document leaflet modal popup graphs #412

Closed davidhodge931 closed 2 years ago

davidhodge931 commented 2 years ago
  leaf_draw <- function() {
    # add leaflet code from make_data_vis.R
    # change any placeholder character values to input widgets
    # refer to a reactive map_data object as map_data()
    # use reactive radius for points that get bigger as the user zooms in, if necessary

    size_reactive <- ifelse(input$map_zoom < 6, 1.5,
             ifelse(input$map_zoom < 7, 2, 
                    ifelse(input$map_zoom < 8, 3, 4)))

    title <- paste0("Monitored trends, 2008\u201317")

    leaf_sf_col(
      map_data(),
      col_var = trend_category,
      size_point = size_reactive,
      col_title = title,
      layer_id_var = site_id,
      popup = FALSE
    )
  }

  observeEvent(input$map_marker_click, {

    site_median <- map_data() %>% 
      filter(site_id == input$map_marker_click$id) %>% 
      pull(median)

    showModal(
      modalDialog(
        renderPlot(
          gg_histogram(map_data(), median, 
                    title = paste0(input$map_marker_click$id, " compared to all sites"), 
                     theme = gg_theme(font = "Helvetica", 
                                      size_title = 16,  size_body = 15, 
                                      gridlines_h = T, gridlines_v = T)) +
            ggplot2::geom_vline(ggplot2::aes(xintercept = site_median), col = "red")
        ),
        easyClose = TRUE
      )
    )
  })
davidhodge931 commented 2 years ago

From template css, delete:

.navbar-static-top {
    z-index: 1500;
}
davidhodge931 commented 2 years ago

Done :)