I am currently looking for a method to change parameters of the print function of a normal web page. In fact, when you press CTRL P, it opens a little window where you can print a file as PDF, and I am trying to change some informations on it. For example, the title of the first page and the name of the PDF file. If someone have an idea of how to do that in my R shiny code, let me know as soon as possible. Thank you :)
CodePudding user response:
The dialog to print the webpage to a pdf file is a feature of the browser and can not be directly manipulated using shiny. Howeve, the browser uses HTML meta data from the head tag e.g. to print the title. You can add these tags to your shiny webpage:
library(shiny)
ui <- fluidPage(
tags$head(
# Define the title in both the browser tab name and pdf print header
tags$title("My fancy shiny title")
),
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput(
inputId = "bins",
label = "Number of bins:",
min = 1,
max = 50,
value = 30
)
),
mainPanel(
plotOutput(outputId = "distPlot")
)
)
)
server <- server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful$waiting
bins <- seq(min(x), max(x), length.out = input$bins 1)
hist(x,
breaks = bins, col = "#75AADB", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times"
)
})
}
shinyApp(ui, server)
You might also want to add shiny::tags$style
tags e.g. to add @media
rules to customize the print layout e.g. to remove the sidebar or buttons.