Skip to content

Commit

Permalink
module utils
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Apr 17, 2024
1 parent e4fe755 commit a4870d5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 57 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ importFrom(datamods,import_modal)
importFrom(datamods,import_server)
importFrom(datamods,set_i18n)
importFrom(datamods,show_data)
importFrom(datamods,update_variables_server)
importFrom(datamods,update_variables_ui)
importFrom(ggplot2,"%+%")
importFrom(ggplot2,aes)
importFrom(ggplot2,coord_flip)
Expand Down
17 changes: 1 addition & 16 deletions R/esquisse-server.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,7 @@ esquisse_server <- function(id,
show_data_server("show_data", reactive(controls_rv$data))

# update variable modal
observeEvent(input$update_variable, {
showModal(modalDialog(
title = tagList(
i18n("Update & select variables"),
button_close_modal()
),
datamods::update_variables_ui(ns("update_variable"), title = NULL),
easyClose = TRUE,
size = "l",
footer = NULL
))
})
updated_data <-datamods::update_variables_server(
id = "update_variable",
data = reactive(data_chart$data)
)
updated_data <- update_vars_server("update_variable", reactive(data_chart$data))
observeEvent(updated_data(), {
data_chart$data <- updated_data()
})
Expand Down
2 changes: 1 addition & 1 deletion R/esquisse-ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ make_btn_header <- function(.list) {
function(id) NULL
},
update_variable = if (isTRUE(.list$update_variable)) {
btn_header(i18n("Update variable"), "brackets-angle")
update_vars_ui
} else {
function(id) NULL
},
Expand Down
40 changes: 0 additions & 40 deletions R/module-show-data.R

This file was deleted.

72 changes: 72 additions & 0 deletions R/module-utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

# Show data -------------------------------------------------------------------------

#' @importFrom shiny NS
show_data_ui <- function(id) {
ns <- NS(id)
btn_header(i18n("Show data"), "table")(ns("btn"))
}

#' @importFrom shiny moduleServer observeEvent showNotification reactive
#' @importFrom datamods show_data
show_data_server <- function(id, data_r = reactive(NULL)) {
moduleServer(
id,
function(input, output, session) {

observeEvent(input$btn, {
data <- data_r()
if (!is.data.frame(data)) {
showNotification(
ui = "No data to display",
duration = 700,
id = paste("esquisse", sample.int(1e6, 1), sep = "-"),
type = "warning"
)
} else {
show_data(data, title = i18n("Dataset"), type = "modal")
}
})

}
)
}




# Update vars -----------------------------------------------------------------------

#' @importFrom shiny NS
update_vars_ui <- function(id) {
ns <- NS(id)
btn_header(i18n("Update variables"), "brackets-angle")(ns("btn"))
}

#' @importFrom shiny moduleServer observeEvent modalDialog showModal reactive
#' @importFrom datamods update_variables_ui update_variables_server
update_vars_server <- function(id, data_r = reactive(NULL)) {
moduleServer(
id,
function(input, output, session) {
ns <- session$ns
observeEvent(input$btn, {
showModal(modalDialog(
title = tagList(
i18n("Update & select variables"),
button_close_modal()
),
datamods::update_variables_ui(ns("update_variable"), title = NULL),
easyClose = TRUE,
size = "l",
footer = NULL
))
})
updated_data <-datamods::update_variables_server(
id = "update_variable",
data = data_r
)
return(updated_data)
}
)
}

0 comments on commit a4870d5

Please sign in to comment.