I have a simple shiny application where in when you click on the plus sign, the drop down appears.That is fine. (This is a rough table. Do not worry)
library(shiny)
library(DT)
ui <- fluidPage(
dataTableOutput("ry")
)
server <- function(input, output, session) {
output$ry <- renderDataTable({
callback <- paste0("
table.column(1).nodes().to$().css({cursor: 'pointer'});
var format = function(d) {
return '<body><div style=\"background-color:#cbe6ef; padding: .5em;text-align:center;\"><table><tr><td><b>Tag</b></td><td><b>Number of Reviews</b></td><td><b> Share of Reviews </b></td><td><b> Click for Reviews </b></td> <tr><td> null </td><td>' + d[50] + '</td><td>' + d[51] + '</td><td>' + d[52] + '</td></tr> <tr><td>' + d[45] + '</td><td>' + d[46] + '</td><td>' + d[47] + '</td><td>' + d[48] + '</td></tr> <tr><td>' + d[41] +'</td></tr> </tr></table></div></body>';};
table.on('click', 'td.details-control', function() {
var td = $(this), row = table.row(td.closest('tr'));
if (row.child.isShown()) {
row.child.hide();
td.html('+');
} else {
row.child(format(row.data())).show();
td.html('−');
}
});")
datatable(cbind(Plus = '+',iris),
escape = F,
rownames = F,options = list( columnDefs = list(
list(orderable = FALSE, className = 'details-control', targets = c(0))
)),
callback = JS(callback
))
})
}
shinyApp(ui, server)
But as you can see there are null values here. So when there are null values , that entire row should get removed. So I tried with below stuffs but not working
library(shiny)
library(DT)
ui <- fluidPage(
dataTableOutput("ry")
)
server <- function(input, output, session) {
output$ry <- renderDataTable({
callback <- paste0("
table.column(1).nodes().to$().css({cursor: 'pointer'});
var format = function(d) {
return '<body><div style=\"background-color:#cbe6ef; padding: .5em;text-align:center;\"><table><tr><td><b>Tag</b></td><td><b>Number of Reviews</b></td><td><b> Share of Reviews </b></td><td><b> Click for Reviews </b></td> <tr><td> null </td><td>' + d[50] + '</td><td>' + d[51] + '</td><td>' + d[52] + '</td></tr> <tr><td>' + d[45] + '</td><td>' + d[46] + '</td><td>' + d[47] + '</td><td>' + d[48] + '</td></tr> <tr><td>' + d[41] +'</td></tr> </tr></table></div><script type='text/javascript'> document.querySelectorAll('td').forEach((item) => {if (item.textContent.includes('null')) {item.parentElement.remove();}});</script></body>';};
table.on('click', 'td.details-control', function() {
var td = $(this), row = table.row(td.closest('tr'));
if (row.child.isShown()) {
row.child.hide();
td.html('+');
} else {
row.child(format(row.data())).show();
td.html('−');
}
});")
datatable(cbind(Plus = '+',iris),
escape = F,
rownames = F,options = list( columnDefs = list(
list(orderable = FALSE, className = 'details-control', targets = c(0))
)),
callback = JS(callback
))
})
}
shinyApp(ui, server)
Can anyone help me here please