|
1 | | -#' The application server-side |
2 | | -#' @param input,output,session Internal parameters for {shiny}. |
| 1 | +#' Server-Side Application |
| 2 | +#' @param input,output,session Internal parameters for 'shiny'. |
3 | 3 | #' @noRd |
4 | 4 | app_server <- function(input, output, session) { |
5 | | - # Data ---- |
6 | | - |
7 | 5 | 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 |
37 | | - ) |
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 | | - }) |
| 6 | + rates_data <- azkit::read_azure_parquet(container, "rates", "dev") |
| 7 | + |
| 8 | + providers_lookup <- jsonlite::read_json( |
| 9 | + app_sys("app", "data", "datasets.json"), |
| 10 | + simplify_vector = TRUE |
| 11 | + ) |
| 12 | + |
| 13 | + strategies_lookup <- jsonlite::read_json( |
| 14 | + app_sys("app", "data", "mitigators.json"), |
| 15 | + simplify_vector = TRUE |
| 16 | + ) |
| 17 | + |
| 18 | + selected_provider <- mod_select_provider_server( |
| 19 | + "mod_select_provider", |
| 20 | + providers_lookup |
| 21 | + ) |
| 22 | + selected_strategy <- mod_select_strategy_server( |
| 23 | + "mod_select_strategy", |
| 24 | + strategies_lookup |
| 25 | + ) |
| 26 | + |
| 27 | + mod_plot_trend_server( |
| 28 | + "mod_plot_trend", |
| 29 | + rates_data, |
| 30 | + selected_provider, |
| 31 | + selected_strategy |
| 32 | + ) |
58 | 33 | } |
0 commit comments