I am wondering whether it's possible to link a local pdf file to an action button in Shiny. For example, I have a manual button. A pdf file will be opened once the user clicks the "Manual" action button.
Thanks in advance.
I am wondering whether it's possible to link a local pdf file to an action button in Shiny. For example, I have a manual button. A pdf file will be opened once the user clicks the "Manual" action button.
Thanks in advance.
This is a solution that is going to display your pdf file in a new browser window after clicking on a button.
www
folder in the same directory as the ui.R
scriptxyz.pdf
in www
folderonclick
to the actionButton
and set it to "window.open('xyz.pdf')"
Example:
library(shiny)
ui <- fluidPage(
actionButton("pdf", "Manual", onclick = "window.open('xyz.pdf')")
)
server <- function(input, output) { }
shinyApp(ui = ui, server = server)
UPDATE:
Another way to open a pdf stored on the local drive is to observe for an event when an action button is pressed and then use built-in R function file.show()
:
library(shiny)
ui <- fluidPage(
actionButton("pdf", "Manual")
)
server <- function(input, output) {
observeEvent(input$pdf, {
# Absolute path to a pdf
file.show(file.path(R.home(), "doc", "NEWS.pdf"))
})
}
shinyApp(ui = ui, server = server)
© 2022 - 2024 — McMap. All rights reserved.