将引导工具提示添加到闪亮应用程序中的列标题

问题描述:

我试图将工具提示添加到数据表的每个列标题中,但是失败了.有人可以教我如何使用jQuery.

I am trying to add tooltips to each column header of the data table, but failed. Could anybody teach me how to do this using jQuery.

谢谢

  shinyApp(
    ui = fluidPage(
      fluidRow(
        tags$head(
          tags$script( src = "https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"),
          tags$script( src = "http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js")
        ),


        column(12,    tableOutput('table')




        )
      )
    ),
    server = function(input, output) {
      output$table <- renderTable(iris)
    }
  )


  # DataTables example
  shinyApp(
    ui = fluidPage(
      fluidRow(
        column(12,
               dataTableOutput('table')
        )
      )
    ),
    server = function(input, output) {
      output$table <- renderDataTable(iris)
      tags$head(tags$script("
        $('table th').each(    function(){ console.log( $(this).text());
                             $(this).attr('data-toggle', 'tooltip')
                            $(this).attr('title', 'example text')
                            $(this).tooltip();
        );




        "))
    }
  )

向initComplete添加js函数以解决问题

Add a js function to initComplete solve the problem

output$table <- renderDataTable(iris,
                                  options = list(
                                    pageLength = 5,
                                    initComplete = I("function(settings, json) {alert('Done.');
                                      $('th').each( function(){this.setAttribute( 'title', 'Hihihi' );});  
                                      $('th').tooltip(); 

                                     }")
                                  )