Popup message box in Shiny datatables for row names?

I’m trying to include something like a popup message box with info about the rownames when the user hovers over / clicks on the row names of a datatable. How can I do that in R shiny?

Hi nan,

You may want to look into popify, part of the shinyBS package.

Hope this helps!

You could use child rows for this. It requires a bit of JS code but see a couple examples of it in action below.

https://rstudio.github.io/DT/002-rowdetails.html

http://www.reigo.eu/2018/04/extending-dt-child-row-example/

I am trying to add different messages to different rows in datatable in R shiny. But when I run the below code (this is just an example code, but I want something like that), it only adds the message to one of the row. How can I add to multiple rows?

library(shiny)
library(shinyBS)
library(DT)
library(formatR)
ui <- fluidPage(
  titlePanel('All you want to know about Titanic'),
  fluidRow(
    
    bsButton('tbutton','Lift Titanic'),
    br(),
    bsTooltip('tbutton', 'This button will inflate a balloon'),
    width=2),
  mainPanel(dataTableOutput('titanic')
  )
)

server <- function(input, output) {
  
  tdata <- as.data.frame(Titanic)
  tdata <- cbind(tdata,tdata)
  output$titanic <- DT::renderDataTable({
    
    header <-  htmltools::withTags(table(
      
      class = 'display',
      thead(
        tr(
          th(rowspan = 1, 'PassengerID'),
          th(colspan = 6, 'Titanic1'),
          th(colspan = 6, 'Titanic2')),
        tr(lapply(c(" ", rep(colnames(as.data.frame(Titanic)), 2)), th))
      )
    )
    )
    
  
  
    rownames(tdata)[1] <- as.character(popify(actionLink(inputId=paste("t_",i,sep=""), label=rownames(tdata)[1]), title=paste("message1"), placement = "bottom", trigger = "hover", options = NULL))
    rownames(tdata)[2] <- as.character(popify(actionLink(inputId=paste("t_",i,sep=""), label=rownames(tdata)[2]), title=paste("message2"), placement = "bottom", trigger = "hover", options = NULL))
    rownames(tdata)[3] <- as.character(popify(actionLink(inputId=paste("t_",i,sep=""), label=rownames(tdata)[3]), title=paste("message3"), placement = "bottom", trigger = "hover", options = NULL))
    
    
    datatable(tdata, container=header, rownames=TRUE, selection='none', escape=FALSE)
  })
}

shinyApp(ui = ui, server = server)

Hi there,

I don't see an object i, and it threw an error when I tried to run your code. For an unsophisticated solution, I changed i to 1, 2, and 3 in your rownames statements, like so:

    rownames(tdata)[1] <- as.character(popify(actionLink(inputId=paste("t_",1,sep=""), label=rownames(tdata)[1]), title=paste("message1"), placement = "bottom", trigger = "hover", options = NULL))
    rownames(tdata)[2] <- as.character(popify(actionLink(inputId=paste("t_",2,sep=""), label=rownames(tdata)[2]), title=paste("message2"), placement = "bottom", trigger = "hover", options = NULL))
    rownames(tdata)[3] <- as.character(popify(actionLink(inputId=paste("t_",3,sep=""), label=rownames(tdata)[3]), title=paste("message3"), placement = "bottom", trigger = "hover", options = NULL))

Now when I hover over the links, I see the unique messages:

Hope this helps set you in the right direction!

1 Like