Adding dynamic mouseover to all records in a column in a DataTable using Shiny (R)

I was sure that there was already an answer to my question, but no matter how hard I tried, I could not find a solution that could work in this case. Therefore, if it is considered trivial, do not shoot.

Now here is the problem:

Assuming we are rendering a dataTable using Shiny, I would like to capture the identifier of each cell (rowID + columnID) when I hang over the cell and dynamically fetch from the underlying datasets. I know there are already pickup solutions like shinyBS or this example:

#server.R: shinyServer(function(input, output) { dat <- list(iris,cars) output$tabset <- renderUI({ tabs <- list() for(i in c(1,2)){ id <- paste("id",i, sep="") tabs[[i]] <- tabPanel(title=id,DT::dataTableOutput(outputId=id)) #dynamic panels } do.call(tabsetPanel,c(tabs, id='Panel')) }) lapply(1:2,function(i){ id <- paste("id",i, sep="") output[[id]] <- DT::renderDataTable({ dat[[i]]}, extensions = c('Scroller'), options=list(deferRender=TRUE, dom='T<"clear">fitrS', scrollY=540, searchHighlight = TRUE, scrollCollapse=TRUE, autoWidth = TRUE, columnDefs = list(list(width = '60%', targets = '_all', render = JS("function(data, type, row, meta) {", "return type === 'display' && data.length > 5 ?", "'<span title=\"' + data + '\">' + data.substr(0, 5) + '...</span>' : data;", "}" )))), callback = JS('table.page(3).draw(false);'), escape=FALSE, rownames=TRUE,class = 'table-condensed', server=TRUE) }) }) 

And ui.R

  #ui.R: library(shiny) library(DT) ui <- fluidPage( uiOutput('tabset') ) 

There is a mouse pointer that cuts the cell if its length is 5 or more. What I would like to do now is to see if the selected cell is selected from the panel with "id1", from the Sepal.Length column, and the mouse pointer should display data from the panel "id2", which had the same rowId that and in Sepal. Length and should display data from the dist column. Basically, I don’t want to represent static content or just change the line that is already in this cell, but rather dynamically present additional content depending on which cell was dependent. Is this possible with Shiny and JavaScript?

Thanks for any input.

+5
source share

Source: https://habr.com/ru/post/1237556/


All Articles