Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- ui <- fluidPage(
- numericInput("num", "num", 5),
- DT::DTOutput("table")
- )
- makecb <- function(ids) {
- unlist(lapply(ids, function(x) {
- as.character(checkboxInput(paste0("cb_", x), label = paste0("cb_", x)))
- }))
- }
- server <- function(input, output, session) {
- output$table <- DT::renderDataTable({
- DT::datatable(
- data.frame(x = character(), y = character()),
- escape = FALSE,
- options = list(
- preDrawCallback = htmlwidgets::JS('function() { Shiny.unbindAll(this.api().table().node()); }'),
- drawCallback = htmlwidgets::JS('function() { Shiny.bindAll(this.api().table().node()); } ')
- )
- )
- })
- proxy <- DT::dataTableProxy('table', deferUntilFlush = FALSE)
- observe({
- data <- data.frame(
- x = seq(input$num),
- y = makecb(seq(input$num))
- )
- DT::replaceData(proxy, data, resetPaging = FALSE)
- })
- observe({
- ids <- grep("^cb", names(input), value = TRUE)
- values <- sapply(ids, function(id) {
- input[[id]]
- })
- print(t(values))
- })
- }
- shinyApp(ui, server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement