How to link to a file from an included markdown document in a shiny app?


My file (a pdf) is stored in www/.

The app:

    ui = fluidPage(includeMarkdown(here::here("www/rmarkdown.Rmd"))), 
    server = function(input, output) {}

My www/rmarkdown.Rmd contains:


What is the right syntax to link to the pdf file? I tried many variations, none worked.

Any idea what's the proper way to link to (non-image) files from an included Markdown doc?

Hi @Julien,

Are you trying to hyperlink a PDF file inside your R Markdown? What would you want the expected behaviour to be? Opening the PDF file in a separate window?

You may also consider embedding the PDF file inside the HTML file with one of the following commands:

title: "Sweet document"
output: html_document


```{r out.width="100%", out.height="500"}

A fully-scrollable and downloadable PDF is embedded directly in the HTML document. One using Markdown syntax, the other (my preferred) using knitr and chunk opts.

Otherwise, you are probably better off creating a downloadButton/Handler and allow users to download the PDF locally. It's another option.

Thanks Matt!
Yes, I'm just trying to hyperlink to a pdf, very basic stuff.
But I can't figure out the right syntax in the case of markdown content loaded from an includeMarkdown() call.

Here are a few equivalent ways that work for me:

title: "Sweet document"
output: html_document

<a href=www/someFile.pdf>text</a>

htmltools::HTML('<a href=www/someFile.pdf>text</a>')

htmltools::a(href = 'www/someFile.pdf', 'text')

Thanks Matt. None of it is working though.

I even simplified the app a step further linking directly from the ui function but no luck.


ui <- fluidPage(
  shiny::a("one",target="_blank", href="www/someFile.pdf"),
  htmltools::HTML('<a href=www/someFile.pdf>two</a>'),
  htmltools::a(href = 'www/someFile.pdf', 'three'),
server <- function(input, output) {}
shinyApp(ui, server)

My project folder contains:


Still get a "Not found" error message in the browser for all links when clicked. :thinking:

OK, I found the solution.
I needed to add shiny::addResourcePath('www', here::here("www")) to my server function. I thought it was taken care of automatically by Shiny.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.