Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
933 views
in Technique[技术] by (71.8m points)

r - Include link to local html file in DataTable in 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?

This is my code

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...