I'm trying to add checboxes to my datatable in shiny and retrie later all the checked lines to other manipulation.
I have a function to add checkboxes to my data table (Select column). But when I try to build my datatable, there's text in the checkbox area.
Can anyone help me solve this problem? Thank you.
The function :
input_checkbox_ui_tiers_concours <- function(id, data, session, checked = FALSE) {
ns <- NS(id)
tag <- lapply(
X = data,
FUN = function(x) {
# res <- checkboxInput(inputId = ns(paste0("check_", x)), label = NULL, value = FALSE)
res <- tags$input(id = ns(paste0("check_", x)), type = "checkbox", style = "float: right;")
if(checked) res$attribs$checked <- "checked"
doRenderTags(res)
}
)
unlist(tag, use.names = FALSE)
}
Datatable :
data_react_dt = reactive({
data_p = copy(data_perim_rv$df_perim_filtre)
test5 <<- data_perim_rv$df_perim_filtre
col_factor = data_p %>% lapply(is.factor) %>% .[. == TRUE] %>% names
col_factor = data_p%>% names %>% str_subset( "^DAT", negate = TRUE)
col_factor2 = data_p[, col_factor] %>% lapply( function(x){ !is.factor(x)} ) %>% .[. == TRUE] %>% names
setDT(data_p)
data_p[ , (col_factor2) := lapply(.SD, function(x) { as.factor(x) }), .SDcols = col_factor2]
data_p[ , (col_factor) := lapply(.SD, function(x) { fct_explicit_na(x, "Non renseigné") }), .SDcols = col_factor]
data_p[ , ":=" ( Indic_Projet_Lab = Indic_Projet_Lab %>% fct_recode( "Non renseigné" = "") ) ]
col_date = data_p %>% names %>% str_subset( "^DAT")
data_p[ , (col_date) := lapply(.SD, as.character ), .SDcols = col_date ]
setDF(data_p)
data_p
})
data_react_dt2 = reactive({
# col_label_reactive()
data = data_react_dt()
if(length( col_label_reactive())>0)
data= data[, col_label_reactive()]
# toto<<-data
# print(names(data))
data
})
output[['dt_suivi_dt']] <- DT::renderDataTable(server = TRUE,
{
data <- data_react_dt2()
data$Select <- input_checkbox_ui_tiers_concours(ns("select_tiers_concours"),data$ID, session = session)
data <- data %>% dplyr::select(Select, everything())
datatable(
data <- data
)
data
}
Aucun commentaire:
Enregistrer un commentaire