Combining Conditional Formatting with Tooltips in Shiny DataTable

I'm facing a challenge with my Shiny app's DataTable, and I hope someone here can provide some insights.

Goal: I wish to display data in my DataTable where each cell has an associated tooltip to display related data. Additionally, I want the background color of the cell to be conditionally formatted based on its value.

What I've Tried:

  1. Tooltips: I've managed to display tooltips using dplyr::mutate as follows:
dplyr::mutate(
      stat_with_tooltip = paste0(
        '<span title="Related data: ', 
        relatedData, 
        '%">', 
        .data[[stat]], 
        '</span>'
      )

This renders the tooltip as expected.

  1. Conditional Formatting: Without tooltips, I can achieve conditional formatting with the following:
    DT::formatStyle(columns = 2:5, backgroundColor = DT::styleInterval(10, c('red', 'green'))

Problem: When I combine both the tooltip and conditional formatting, things break because the formatStyle function can't work on the HTML string from the tooltip.

Ask: Has anyone encountered a similar problem or have a solution that allows both tooltips and conditional formatting in a Shiny DataTable?

Any help or pointers would be much appreciated!

my approach would be to do your own html/css based formatting in the same mutate where you make the element , and forget using DT::formatStyle

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.