I have a datatable in Shiny where I want to insert a column with checkboxes. This works also so far without problems.
However, these checkboxes should be selected automatically when a certain condition is met. I have used the iris dataset as an example and would like to set a mark in the respective checkbox if the value in Sepal.Length
is greater than 5.
With my current approach, all checkboxes are selected and unfortunately not only those that meet the condition.
Can anyone help me with my problem?
library(tidyverse)
library(shiny)
library(DT)
shinyInput<-function(FUN, len, id, ...) {
inputs <- character(len)
for (i in seq_len(len)) {
inputs[i] <- as.character(FUN(paste0(id, i), label=NULL, ...))
}
inputs
}
ui <- fluidPage(
dataTableOutput("table")
)
server <- function(input, output) {
table1 <- iris %>%
mutate(Check = shinyInput(checkboxInput, nrow(iris), 'check1', value = ifelse(Sepal.Length >= 5, TRUE, FALSE)))
output$table <- renderDataTable({
DT::datatable({table1},
escape = F)
})
}
shinyApp(ui = ui, server = server)
Current output:
Desired output:
Aucun commentaire:
Enregistrer un commentaire