行名称的Shiny数据表中的工具提示或弹出框? [英] tooltip or popover in Shiny datatables for row names?

查看:231
本文介绍了行名称的Shiny数据表中的工具提示或弹出框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户将鼠标悬停在/单击数据表的行名时,我一直试图包含诸如工具提示或弹出窗口之类的附加信息,因此他们不必查找某些定义,而我目前在不同的tabPanel上。这是一个工作示例:

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 have to look up some definitions, which I currently have on a different tabPanel. Here's a working example:

library(shiny)
library(DT)
library(shinyBS)

# Define server for the Shiny app
shinyServer(function(input, output,session) {

tdata <- as.data.frame(iris)

# Render table here 
output$mytable <- DT::renderDataTable(DT::datatable(

   tdata[1:5,],

   options = list(paging = FALSE, searching = FALSE, info = FALSE, sort = FALSE,
                 columnDefs=list(list(targets=1:4, class="dt-right")) ),

   rownames = paste("rowname",1:5),

   container = htmltools::withTags(table(
      class = 'display',
      thead(
         tr(lapply(rep(c('ratios','name1', 'name2', 'name3','name4','name5'), 1),th))
      )
   ))
))

}) # end of shinyServer function



ui.R:



ui.R:

library(shiny)
library(DT)
library(shinyBS)

shinyUI(
   mainPanel(
      DT::dataTableOutput("mytable")
   )   
)      

请注意,我看过以下讨论主题,但没有成功:
表列的R闪亮鼠标悬停文本,以及
将启动工具提示添加到闪亮的应用程序的列标题中
所以我在想DT-package选项中的内容,或使用ShinyBS软件包的内容(如 bsTooltip)或添加一些HTML或JS。
Shiny不自然地为数据表中的此工具提示/弹出窗口功能...!?

Please note that I have seen the following discussion topics, but without success: R shiny mouseover text for table columns, as well as Add bootstrap tooltip to column header in shiny app So I'm thinking either something within the DT-package options, or something using the shinyBS package (like 'bsTooltip') or add some HTML or JS. This tooltip/popover feature does not seem to be naturally supported by Shiny for within datatables...!?

推荐答案

此代码有效,但在客户端模式下运行。为了简化起见,我使用了虹膜数据集的前五行,但我想这个主意很明确。如果将鼠标悬停在行名称上,将显示工具提示。

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)
    }) 

这篇关于行名称的Shiny数据表中的工具提示或弹出框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆