Shiny - true or false value when check a checkbox in datatable

后端 未结 1 924
北恋
北恋 2021-01-27 10:56

i have problem with R shiny code, what i must do, when i want to see the true or false value in checkbox? because when i try print(input$row1) the result is NULL, and when i giv

相关标签:
1条回答
  • 2021-01-27 11:33

    See short example ( only for row1)

    1) You can use Shiny.bindAll

    2) You need to see print in observe

     library(shiny)
    library(DT)
    mymtcars = mtcars
    mymtcars$id = 1:nrow(mtcars)
    runApp(
      list(ui = pageWithSidebar(
        headerPanel('Examples of DataTables'),
        sidebarPanel(
          checkboxGroupInput('show_vars', 'Columns to show:', names(mymtcars),
                             selected = names(mymtcars))
          ,textInput("collection_txt",label="Foo")
        ),
        mainPanel(
          DT::dataTableOutput("mytable")
        )
      )
      , server = function(input, output, session) {
    
        observe({
          print(input$row1)
        })
    
        output$mytable = DT::renderDataTable({
          #Display table with checkbox buttons
          DT::datatable(cbind(Pick=paste0('<input type="checkbox" id="row', mymtcars$id, '" value="', mymtcars$id, '">',""), mymtcars[, input$show_vars, drop=FALSE]),
                        options = list(orderClasses = TRUE,
                                       lengthMenu = c(5, 25, 50),
                                       pageLength = 25 ,
    
                                       drawCallback= JS(
                                         'function(settings) {
                                             Shiny.bindAll(this.api().table().node());}')
                        ),selection='none',escape=F)
    
    
        } )
    
      })
    )
    
    0 讨论(0)
提交回复
热议问题