#' instant_risk_overview UI Function #' #' @description A shiny Module. #' #' @param id,input,output,session Internal parameters for {shiny}. #' #' @noRd #' #' @importFrom shiny NS tagList mod_instant_risk_overview_ui <- function(id){ ns <- NS(id) choices <- seq(length(rvgest::rulesets$rules)) names(choices) <- paste0(choices, ". ", rvgest::rulesets$rules) tagList( fluidRow( column(width = 6, selectInput( ns("ruleset"), "Rule set", choices, selected = NULL, multiple = FALSE, selectize = TRUE, width = NULL, size = NULL )), column(width = 6, dateInput(ns("date"), "Date:", value = Sys.Date()))), fluidRow( lapply(seq.int(nrow(rvgest::lakes)), function(i) { column(width = 3, sliderInput(ns(paste0("V", i)), label = paste(rvgest::lakes$name[i], "lake (hm3)"), value = round(getObjectiveStorage()[rvgest::lakes$name[i]]), min = rvgest::lakes$min[i], max = rvgest::lakes$max[i])) }) ), # tableOutput(ns("table")) plotOutput(ns("plot")) ) } #' instant_risk_overview Server Function #' #' @noRd #' @import ggplot2 mod_instant_risk_overview_server <- function(id, con) { moduleServer(id, function(input, output, session){ ns <- session$ns df <- reactive({ storages <- c(input$V1, input$V2, input$V3, input$V4) names(storages) <- lakes$name golem::print_dev(storages) calcInstantRisk(con, input$ruleset, input$date, storages) }) # output$table <- renderTable(df()) output$plot <- renderPlot( ggplot(df(), aes(x = reorder(objective, prob), y = prob)) + geom_col(aes(fill = level)) + scale_y_continuous(labels = scales::percent_format(accuracy = 1)) + coord_flip()) }) } ## To be copied in the UI # mod_instant_risk_overview_ui("instant_risk_overview_ui_1") ## To be copied in the server # mod_instant_risk_overview_server("instant_risk_overview_ui_1")