问题
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