Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. library(shiny)
  2. ui <- fluidPage(
  3. numericInput("num", "num", 5),
  4. DT::DTOutput("table")
  5. )
  6.  
  7. makecb <- function(ids) {
  8. unlist(lapply(ids, function(x) {
  9. as.character(checkboxInput(paste0("cb_", x), label = paste0("cb_", x)))
  10. }))
  11. }
  12.  
  13. server <- function(input, output, session) {
  14. output$table <- DT::renderDataTable({
  15. DT::datatable(
  16. data.frame(x = character(), y = character()),
  17. escape = FALSE,
  18. options = list(
  19. preDrawCallback = htmlwidgets::JS('function() { Shiny.unbindAll(this.api().table().node()); }'),
  20. drawCallback = htmlwidgets::JS('function() { Shiny.bindAll(this.api().table().node()); } ')
  21. )
  22. )
  23. })
  24.  
  25. proxy <- DT::dataTableProxy('table', deferUntilFlush = FALSE)
  26.  
  27. observe({
  28. data <- data.frame(
  29. x = seq(input$num),
  30. y = makecb(seq(input$num))
  31. )
  32. DT::replaceData(proxy, data, resetPaging = FALSE)
  33. })
  34.  
  35. observe({
  36. ids <- grep("^cb", names(input), value = TRUE)
  37. values <- sapply(ids, function(id) {
  38. input[[id]]
  39. })
  40. print(t(values))
  41. })
  42. }
  43. shinyApp(ui, server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement