It helped for me. But I just added another column with html tags to open another window. But the tags are gettting printed as it is and open another window. (Click on more info)
library(tidyverse)
library(DT)
library(xtable)
library(shiny)
samdt <- structure(list(Domain = c("a", "a", "b", "b", "b"),
sub_domain = c("a1", "a1", "b1", "a1", "b1"),
Reviews = c(1234, 2311, 3123, 4311, 5211),
Ratings = c(1,2,1,2,1),
text = c("asd","dfdsf","sdfs","sdfs","sdf")), row.names = c(NA,-5L), class = c("tbl_df", "tbl", "data.frame"))
new_sam <- samdt %>% group_by(Domain) %>% summarise(nReviews = n())
subs <- samdt %>% group_by(Domain, sub_domain) %>% summarise(nReviews = n(),Ratings = toString(Ratings), Text = toString(text),
html = HTML("<body>
<table border='1'>
<tr onclick='window.open(\"http://www.google.com\")'>
<td>Open Another Window</td>
</tr>
</table>
</body>")) %>% nest() %>% rowwise() %>% mutate(
htmltab = HTML(print(xtable(data),type="HTML"))
)
samdt_x <- left_join(new_sam,subs)
add_collapse_content <- function(x, id) {
tagList(
tags$button(
"data-toggle" = "collapse",
"data-target" = paste0("#", id),
"More Info"
),
div(
"id" = id,
"class" = "collapse",
x
)
) %>% as.character()
}
samdt_x2 <- samdt_x %>% rowwise() %>% mutate(html_buttons =
add_collapse_content(htmltab,Domain)) %>%
relocate(html_buttons) %>% select(-data,-htmltab)
library(shiny)
ui <- fluidPage(
DTOutput("table")
)
server <- function(input, output, session) {
output$table <- renderDT({
datatable(samdt_x2,rownames = F,escape = F
,options = list(
columnDefs = list(
list(orderable = FALSE, className = 'details-control', targets = c(0))
))
)})
}
shinyApp(ui, server)