tooltip or popover in Shiny datatables for row names?

前端 未结 2 2125
温柔的废话
温柔的废话 2020-12-18 06:54

I’m stuck with trying to include something like a tooltip or popover with additional info when the user hovers over / clicks on the row names of a datatable, so they don’t h

2条回答
  •  旧巷少年郎
    2020-12-18 07:12

    This code works but running in client side mode. To make it simpler I have used the first five rows of the iris dataset, but I guess the idea is clear. If you hover over the row names the tooltip will be displayed.

    ui.R

        library(shiny)
        library(DT)
        shinyUI(
                mainPanel(
                        DT::dataTableOutput("tbl")
                )   
        )    
    

    server.R

        library(shiny)
        library(DT)
        shinyServer(function(input, output,session) {
                output$tbl = DT::renderDataTable(
                        datatable(iris[1:5, ], callback = JS("
                                        var tips = ['First row name', 'Second row name', 'Third row name',
                                        'Fourth row name', 'Fifth row name'],
                                        firstColumn = $('#tbl tr td:first-child');
                                        for (var i = 0; i < tips.length; i++) {
                                        $(firstColumn[i]).attr('title', tips[i]);
                                        }")), server = FALSE)
        }) 
    

提交回复
热议问题