Include Link to Local HTML File in Datatable in Shiny

Include link to local html file in DataTable in Shiny

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

Link to a local html file on RMarkdown with Shiny

Basically, when we run Shiny app the contents of www folder are internally embedded and we don´t need to include www folder to the href attribute.
But, if we want to "expose" those contents thru runtime: shiny we need to add shiny::addResourcePath() function and specify its folder:

    ---
title: "Rmarkdown with shiny"
output: html_document
runtime: shiny
---

```{r setup, include = FALSE}
library(knitr)
library(shiny)
library(here)
shiny::addResourcePath(prefix = "www", directoryPath = here::here("www"))
```

Relative File Path: [My HTML file](www/my_file.html)

Relative File Path: <a href = "www/my_file.html" target="_blank">My HTML file</a>
Absolute File Path: <a href = "http://www.shinyapps.io/" target="_blank">shinyapps.io</a>

Relative File Path:
```{r shiny-relative-links, echo = FALSE, eval = TRUE}
tags$a(href = "www/my_file.html",
tags$span(style = "color: #03a9f4", "My HTML file"),
target = "_blank")
```

Absolute File Path:
```{r shiny-absolute-links, echo = FALSE, eval = TRUE}
tags$a(href = "http://www.shinyapps.io/",
tags$span(style = "color: #03a9f4", "shinyapps.io"),
target = "_blank")
```

See here for original solution and discussion. Also, Ode to the here package.

put a HTML link to the R Shiny application

Something like this should work:

doc <- tags$html(
tags$body(
a(href="http://www.lalala.com"))
)
cat(as.character(doc))

<html>
<body>
<a href="http://www.lalala.com"></a>
</body>
</html>

Can I put multiple download links in same table cell in shiny?

I think this should do it by replacing the for loop with lapply in the renderUI part and generating the downloadLink as a tagList:

  output$hidden_downloads_panel <- renderUI({
outputlist <- lapply(1:nrow(table), function(i) {
if (table[i,5]!="No panels"){
panels=strsplit(table[i,5], "<br>")
panels=panels[[1]]
lapply(1:length(panels), function(j){
tagList(
downloadLink(paste0("downloadData", i, j, 4), "download", class = "hiddenLink")
)
})
}
})
})

and putting the downloadHandler outputs in a local environment to generate unique IDs with the for loop:

  lapply(1:nrow(table), function(i) {
if (table[i,5]!="No panels")
{
panels=strsplit(table[i,5], "<br>")
panels=panels[[1]]
for (j in 1:length(panels)){
local({
my_j = j
output[[paste0("downloadData", i, my_j, 4)]] <- downloadHandler(
filename=paste("./Gene_panel/", table[i,1], "_", panels[my_j], sep=""),
content = function(file) {
file.copy(paste("./Gene_panel/", table[i,1], "_", panels[my_j], sep=""), file)
}

)
})
}}
})

I had to replace your panels=panels$"Gene panel" line with panels=panels[[1]] to make it work with my test dataframe, I was able to "display" the 6 hidden links of your example data.

How do I add a link to open a pdf file in a new window from my R shiny app?

Put the pdf file inside the "www" directory (it has to be a subdirectory inside the directory where there are ui.r and server.r )

then you can run your shiny with:

a("click on me",target="_blank",href="myfile.pdf")


Related Topics



Leave a reply



Submit