在Rstudio DT datatable中是否可以在标题参数中添加超链接?我试了又试,但似乎什么都不能用。我尝试了html标题的w3schools小提琴,我可以在表格的标题中获得一个超链接,但我不知道如何将其转换为DT datatable。我尝试过通过htmltools::调用它,但我只能将其呈现为文本,例如:
datatable(tble
,caption =
htmltools::tags$caption(
style = 'caption-side: top; text-align: left; color:blue; font-size: 12px;',
,htmltools::p('<!DOCTYPE html>
<html><body><a href="http://rstudio.com">RStudio</a></body>
</html>'))
,escape = FALSE
)发布于 2016-07-30 06:43:26
我知道这有点老了,但由于我今天遇到了类似的问题,并找到了答案,我想我应该分享一下。我这样做的方式是使用Shiny的HTML函数来正确地编码html,它将负责必要的转义。示例如下:
DT::datatable(
get(input$dataInput),
caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: Left;',
htmltools::withTags(
div(HTML('Here is a link to <a href="http://rstudio.com">RStudio</a>'))
)
)
)在一个简单闪亮的应用程序中有一个完整的例子:
library(shiny)
library(DT)
data("mtcars")
data("iris")
ui <- fluidPage(
titlePanel("Example Datatable with Link in Caption"),
selectInput('dataInput', 'Select a Dataset',
c('mtcars', 'iris')),
DT::dataTableOutput('example1')
)
server <- function(input, output, session){
output$example1 <- DT::renderDataTable({
# Output datatable
DT::datatable(
get(input$dataInput),
caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: Left;',
htmltools::withTags(
div(HTML('Here is a link to <a href="http://rstudio.com">RStudio</a>'))
)
)
)
})
}
shinyApp(ui = ui, server = server)https://stackoverflow.com/questions/35425121
复制相似问题