I have an interactive RMarkdown document with shiny (i.e. with the line runtime: shiny
in the YAML header) and inside it I would like to create a link to a local html file. But nothing I have tried so far works.
For the sake of the example let's say I have the following files in my working directory:
- work_dir/
- rmarkdown_with_shiny.Rmd
- shiny_app.R
- www/
- my_file.html
What I want to do is to create a link inside rmarkdown_with_shiny.Rmd that opens the file www/my_file.html when clicked.
The code inside the file rmarkdown_with_shiny.Rmd is as follows, includes everything I have tried but so far nothing has worked:
---
title: "Rmarkdown with shiny"
output: html_document
runtime: shiny
---
[link_1](www/my_file.html)
[link_2](my_file.html)
[link_3](file://www/my_file.html)
```{r shiny_links, echo=F, eval=T}
renderUI(tags$a("link_4", href="my_file.html", target="_blank"))
renderUI(tags$a("link_5", href="www/my_file.html", target="_blank"))
renderUI(tags$a("link_6", href="file://www/my_file.html", target="_blank"))
shinyAppFile("shiny_app.R")
```
With the last line shinyAppFile("shiny_app.R")
I can embed an app that contains a working link (when the app is ran alone), but as soon as it is embedded it doesn't work anymore. This is the code inside the shiny_app.R:
library('shiny')
ui <- fluidPage(
htmlOutput("link")
)
server <- function(input, output) {
output$link <- renderUI(tags$a("single_link", href="my_file.html", target="_blank"))
}
shinyApp(ui = ui, server = server)
The confusing part is that this line [link_1](www/my_file.html)
would work if it was only rmarkdown without shiny. And this line would work if it was only a shiny app renderUI(tags$a("single_link", href="my_file.html", target="_blank"))
. But in a rmarkdown file with runtime: shiny
neither of those work.
I would appreciate it a lot if someone could tell me then how to link local html files in rmarkdown + shiny files. Specially if there is a way to do it using shiny functions rather than markdown syntax. But either solution is well welcomed, as long as it creates a functioning link.