Skip to content

Commit

Permalink
added create_column button and module
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Apr 17, 2024
1 parent a4870d5 commit e14c602
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
7 changes: 6 additions & 1 deletion R/esquisse-server.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ esquisse_server <- function(id,
observeEvent(updated_data(), {
data_chart$data <- updated_data()
})


# create column modal
created_col <- create_col_server("create_col", reactive(data_chart$data))
observeEvent(created_col(), {
data_chart$data <- created_col()
})



Expand Down
11 changes: 10 additions & 1 deletion R/esquisse-ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ esquisse_ui <- function(id,
class = "pull-left",
header_btns$import_data(ns("launch_import_data")),
header_btns$show_data(ns("show_data")),
header_btns$update_variable(ns("update_variable"))
header_btns$update_variable(ns("update_variable")),
header_btns$create_column(ns("create_col"))
)
)

Expand Down Expand Up @@ -225,6 +226,7 @@ esquisse_container <- function(width = "100%", height = "700px", fixed = FALSE)
#' @param import_data Show button to import data.
#' @param show_data Show button to display data.
#' @param update_variable Show button to update selected variables and convert them.
#' @param create_column Show button to create a new column based on an expression.
#' @param settings Show button to open settings modal (to select aesthetics to use).
#' @param close Show button to stop the app and close addin.
#'
Expand All @@ -235,12 +237,14 @@ esquisse_container <- function(width = "100%", height = "700px", fixed = FALSE)
esquisse_header <- function(import_data = TRUE,
show_data = TRUE,
update_variable = TRUE,
create_column = TRUE,
settings = TRUE,
close = TRUE) {
list(
import_data = isTRUE(import_data),
show_data = isTRUE(show_data),
update_variable = isTRUE(update_variable),
create_column = isTRUE(create_column),
settings = isTRUE(settings),
close = isTRUE(close)
)
Expand All @@ -264,6 +268,11 @@ make_btn_header <- function(.list) {
} else {
function(id) NULL
},
create_column = if (isTRUE(.list$create_column)) {
create_col_ui
} else {
function(id) NULL
},
settings = if (isTRUE(.list$settings)) {
btn_header(i18n("Display settings"), "gear-fine")
} else {
Expand Down
39 changes: 35 additions & 4 deletions R/module-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,48 @@ update_vars_server <- function(id, data_r = reactive(NULL)) {
i18n("Update & select variables"),
button_close_modal()
),
datamods::update_variables_ui(ns("update_variable"), title = NULL),
datamods::update_variables_ui(ns("mod"), title = NULL),
easyClose = TRUE,
size = "l",
footer = NULL
))
})
updated_data <-datamods::update_variables_server(
id = "update_variable",
res <- datamods::update_variables_server(
id = "mod",
data = data_r
)
return(updated_data)
return(res)
}
)
}





# Create column ---------------------------------------------------------------------

#' @importFrom shiny NS
create_col_ui <- function(id) {
ns <- NS(id)
btn_header(i18n("Create column"), "columns-plus-right")(ns("btn"))
}

#' @importFrom shiny moduleServer observeEvent modalDialog showModal reactive
#' @importFrom datamods update_variables_ui update_variables_server
create_col_server <- function(id, data_r = reactive(NULL)) {
moduleServer(
id,
function(input, output, session) {
ns <- session$ns
observeEvent(input$btn, datamods::modal_create_column(ns("mod")))
res <-datamods::create_column_server(
id = "mod",
data = data_r
)
return(res)
}
)
}


3 changes: 3 additions & 0 deletions man/esquisse-module.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e14c602

Please sign in to comment.