I am trying to get the label of a custom button in a excel file, but I do not know which library to use and how to use it. Currently I use an openxlsx library but in the excel file I get all the code of the button and not just the label
Here is the useful part of my code :
# Creating a custom actionbutton
butt <- function(
id,
ok,
data_value = 0,
vert = FALSE
){
tags$button(
id = id,
`data-value` = data_value,
class = ifelse(vert, "ok", "ko"),
onclick = sprintf('
$(this).toggleClass("ok ko");
$(this).text(function(i, text){
return text === "Ok" ? "Check" : "Ok";
});
$(this).data("value", $(this).data("value") + 1) ;
Shiny.setInputValue("%s", $(this).data("value"))
', id),
ifelse(ok, "Ok", "Check")
)
}
The reactive part in the server :
# server ====
server <- function(input, output, session) {
#Creating the filter rule from the criteria
create_rules <- reactive({
paste(c(input$territoire, input$doc), "== 'Oui'", collapse = " | ")
})
#Extraction of the criteria of the base
FinalData <- eventReactive(input$submit, {
if(is.null(c(input$territoire, input$doc)))
return()
else (base %>% filter_(create_rules()))
})
fdt <- eventReactive(input$submit, {
r$click = data.frame(
id = 1:nrow(FinalData()),
ed = 0 ,
vert = FALSE
)
purrr::map( # Stores the click on the buttons
1:nrow(FinalData()),
~{
observeEvent(input[[sprintf("row%s", .x)]] , {
r$click$ed[.x] <- input[[sprintf("row%s", .x)]]
r$click$vert[.x] %<>% `n'est pas`()
if(r$click$vert[.x]){
counter$countervalue <- counter$countervalue + ((1*100)/nrow(FinalData()))#Incrémente le clic dans la gauge en fonction du nombre de lignes extraites
}
else{
counter$countervalue <- counter$countervalue - ((1*100)/nrow(FinalData()))
}
})
}
)
lien_fiches = createLink(FinalData()$fiches.donnees)
tmp_fdt <- cbind(FinalData()[1:3], lien_fiches)
colnames(tmp_fdt) <- c("A", "B", "C", "E")
tmp_fdt
})
#Réactive général
gfilter <- reactive({
req(fdt())
filtered_data <- base <- fdt() %>%
map_df(enc2native) %>%
mutate(
Validation = purrr::pmap(
r$click,
~ {
butt(
sprintf("row%s", ..1),
ok = ..3,
data_value = ..2,
vert = ..3
)
}
) %>% purrr::map_chr(paste)
) %>%
select("A", "B", "C", "D", "E") %>%
as.data.frame()
#Rendering of the extraction table
output$Synthese <- DT::renderDT(server = FALSE, DT::datatable({
#Affiche le tableau
gfilter()
},
escape = FALSE,
selection = "none",
options = list(
pageLength = 10,
#Cache la colonne "Insee"
columnDefs = list(list(visible=FALSE, targets=3)),
#Extraction header color
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#1A242F', 'color': '#fff'});",
"}"),
dom="frtip",
language = list(paginate =
list('next'="suivant",
'previous'="précédent"),
info = "Pages de _PAGE_ à _PAGES_",
search = "Rechercher",
infoFiltered = "(filtre des _MAX_ lignes)")
)
)
#Sets the color of a line according to a condition
%>% formatStyle('Insee',target="row",backgroundColor = styleEqual('Oui',"#cdd6d8"))
)
}
shinyApp(ui, server)
Thanks !