Skip to content

Commit

Permalink
interactive-plot | reactively show 'show plot' checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
RWParsons committed Jun 9, 2024
1 parent 74510c1 commit 72be097
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
57 changes: 35 additions & 22 deletions app/app/view/main_map/interactive_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,61 @@ box::use(
bslib,
ggplot2,
shiny,
stringr,
)

box::use(
app / logic / scales_and_palettes,
app / logic / utils,
)




#' @export
interactive_plot_ui <- function(id) {
ns <- shiny$NS(id)
shiny$absolutePanel(
id = "plot_panel",
class = "panel panel-default",
fixed = TRUE,
draggable = FALSE,
top = 170,
left = 50,
right = "auto",
bottom = "auto",
width = 120,
height = 50,
shiny$checkboxInput(
ns("show_plot_checkbox"),
shiny$HTML("<b>Show plot</b>"),
value = TRUE
),
shiny$uiOutput(ns("plot_ui"))
)
shiny$uiOutput(ns("interactive_plot_container"))
}

#' @export
interactive_plot_server <- function(id, d_poly) {
interactive_plot_server <- function(id, d_poly, selected_layer) {
shiny$moduleServer(id, function(input, output, session) {
ns <- session$ns

output$interactive_plot_container <- shiny$renderUI({
shiny$req(selected_layer())

if (stringr$str_detect(utils$get_standard_layer_name(selected_layer()), "sa[12]_")) {
chkbox <- shiny$checkboxInput(
ns("show_plot_checkbox"),
shiny$HTML("<b>Show plot</b>"),
value = FALSE
)
} else {
chkbox <- NULL
}

shiny$absolutePanel(
id = "plot_panel",
class = "panel panel-default",
fixed = TRUE,
draggable = FALSE,
top = 170,
left = 50,
right = "auto",
bottom = "auto",
width = 120,
height = 50,
chkbox,
shiny$uiOutput(ns("plot_ui"))
)
})

output$plot_ui <- shiny$renderUI({
shiny$req(input$show_plot_checkbox)
if (!input$show_plot_checkbox) {
return()
}


shiny$plotOutput(
ns("interactive_plot"),
width = 500, height = 400
Expand Down
8 changes: 7 additions & 1 deletion app/app/view/main_map/page.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ server <- function(id) {
)
})

interactive_plot$interactive_plot_server(id = "plot", d_poly = d_poly)
interactive_plot$interactive_plot_server(
id = "plot",
d_poly = d_poly,
selected_layer = shiny$reactive({
input$layer_selection
})
)

shiny$observeEvent(list(proxymap(), d_poly(), input$layer_selection), {
mm$update_map_shapes(
Expand Down

0 comments on commit 72be097

Please sign in to comment.