Add bootstrap tooltip to column header in shiny app

柔情痞子 提交于 2020-01-03 04:30:27

问题


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.

Thanks

  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();
        );




        "))
    }
  )

回答1:


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(); 

                                     }")
                                  )


来源:https://stackoverflow.com/questions/35730287/add-bootstrap-tooltip-to-column-header-in-shiny-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!