在Shiny的DataTable中包含指向本地html文件的链接 [英] Include link to local html file in DataTable in Shiny

查看:172
本文介绍了在Shiny的DataTable中包含指向本地html文件的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包含一个指向本地html文件的链接,该文件位于我闪亮的应用程序的www目录中,位于data.table的列中。点击后,应打开一个新标签,显示html文件。
我已经找到了链接到互联网页面的解决方案,但是如何进行调整,以使Shiny在浏览器中呈现时找到本地文件?

I want to include a link to a local html file, which lives inside the www directory of my shiny app, inside a column in data.table. On click a new tab should open showing the html file. I've found solutions for linking to internet pages, but how do I adjust this, so that Shiny finds the local files, when rendered in a browser?

这是我的代码

library(DT)
library(shiny)

link <- "www/my_html.html"
link <- paste0("<a href='", link,"' target='_blank'>", link,"</a>")  # works fine for global url, but not for local file
df <- data.frame(a = 10.5, b = 48, link = link)

ui <- fluidPage(
  DT::dataTableOutput('table1')
)

server <- function(input, output) {
  output$table1 <- DT::renderDataTable({df}, escape = -3)
}

shinyApp(ui, server)


推荐答案

也许您可以尝试使用闪亮的文件夹运行应用程序。确保my_html.html文件位于闪亮文件夹的 www 文件夹中。

Maybe you could try running your app using a shiny folder. Make sure your my_html.html file is located in a www folder in your shiny folder.

ui.R

library(DT)
library(shiny)

fluidPage(
  DT::dataTableOutput('table1')
)

server.R

library(DT)
library(shiny)

df <- data.frame(a = 10.5, b = 48, link = "<a href='my_html.html' target='blank' >MyFile</a>")

function(input, output) {
  output$table1 <- DT::renderDataTable({df}, escape = FALSE)
}

这篇关于在Shiny的DataTable中包含指向本地html文件的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆