Guest User

Untitled

a guest
Nov 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. library(shiny)
  2. library(DT)
  3.  
  4. M<-mtcars[1:5,] %>%
  5. {mutate(.,names=gsub(" ","_",row.names(.)))} %>%
  6. mutate(.,cb=
  7. Map(function(x,y){
  8. sprintf('<input type="checkbox" name="%s" value="%s"/>',x,y)
  9. },
  10. x=names,
  11. y=TRUE
  12. )
  13.  
  14. ) %>%
  15. select(mpg,cyl,names,cb)
  16.  
  17. shinyApp(
  18. ui = shinyUI(fluidPage(
  19.  
  20. titlePanel("DataTable_with_CheckBox"),
  21. sidebarLayout(
  22. sidebarPanel(
  23. ),
  24. mainPanel(
  25. DT::dataTableOutput('foo')
  26. )
  27. )
  28. )),
  29. server =
  30. shinyServer(function(input, output) {
  31.  
  32.  
  33. output$foo = DT::renderDataTable(
  34. M, escape = FALSE, selection = 'none', server = T,
  35. options = list(dom = 't', paging = FALSE, ordering = FALSE),
  36. callback = JS("table.rows().every(function(i, tab, row) {
  37. var $this = $(this.node());
  38. $this.attr('id', this.data()[0]);
  39. $this.addClass('shiny-input-radiogroup');
  40. });
  41. Shiny.unbindAll(table.table().node());
  42. Shiny.bindAll(table.table().node());")
  43. )
  44.  
  45.  
  46. })
  47. )
Add Comment
Please, Sign In to add comment