|
2 | 2 | #' @param input,output,session Internal parameters for {shiny}. |
3 | 3 | #' @noRd |
4 | 4 | app_server <- function(input, output, session) { |
5 | | - output$distPlot <- shiny::renderPlot({ |
6 | | - x <- datasets::faithful[, 2] |
7 | | - bins <- seq(min(x), max(x), length.out = input$bins + 1) |
8 | | - |
9 | | - # draw the histogram with the specified number of bins |
10 | | - graphics::hist( |
11 | | - x, |
12 | | - breaks = bins, |
13 | | - col = "darkgray", |
14 | | - border = "white", |
15 | | - xlab = "Waiting time to next eruption (in mins)", |
16 | | - main = "Histogram of waiting times" |
| 5 | + # Data ---- |
| 6 | + |
| 7 | + container <- azkit::get_container(Sys.getenv("AZ_CONTAINER_INPUTS")) |
| 8 | + rates <- azkit::read_azure_parquet(container, "rates", "dev") |
| 9 | + |
| 10 | + # Reactives ---- |
| 11 | + |
| 12 | + selected_provider <- shiny::reactive(input$provider_select) |
| 13 | + selected_strategy <- shiny::reactive(input$strategy_select) |
| 14 | + |
| 15 | + rates_prepared <- shiny::reactive({ |
| 16 | + rates |> |
| 17 | + dplyr::filter( |
| 18 | + .data$provider == selected_provider(), |
| 19 | + .data$strategy == selected_strategy() |
| 20 | + ) |> |
| 21 | + dplyr::arrange(.data$fyear) |
| 22 | + }) |> |
| 23 | + shiny::bindEvent(selected_provider(), selected_strategy()) |
| 24 | + |
| 25 | + # Observers ---- |
| 26 | + |
| 27 | + shiny::observe({ |
| 28 | + providers <- jsonlite::read_json( |
| 29 | + app_sys("app", "data", "datasets.json"), |
| 30 | + simplify_vector = TRUE |
| 31 | + ) |
| 32 | + provider_choices <- purrr::set_names(names(providers), providers) |
| 33 | + shiny::updateSelectInput( |
| 34 | + session, |
| 35 | + "provider_select", |
| 36 | + choices = provider_choices |
17 | 37 | ) |
18 | 38 | }) |
| 39 | + |
| 40 | + shiny::observe({ |
| 41 | + strategies <- jsonlite::read_json( |
| 42 | + app_sys("app", "data", "mitigators.json"), |
| 43 | + simplify_vector = TRUE |
| 44 | + ) |
| 45 | + strategy_choices <- purrr::set_names(names(strategies), strategies) |
| 46 | + shiny::updateSelectInput( |
| 47 | + session, |
| 48 | + "strategy_select", |
| 49 | + choices = strategy_choices |
| 50 | + ) |
| 51 | + }) |
| 52 | + |
| 53 | + # Outputs ---- |
| 54 | + |
| 55 | + output$rates_plot <- shiny::renderPlot({ |
| 56 | + rates_prepared() |> plot_rates() |
| 57 | + }) |
19 | 58 | } |
0 commit comments