简体   繁体   中英

Changing CTRL+P of a web page using R shiny

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

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 eg 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 eg to add @media rules to customize the print layout eg to remove the sidebar or buttons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM