我目前正在尋找一種方法來更改普通網頁的列印功能的引數。事實上,當您按 CTRL P 時,它會打開一個小視窗,您可以在其中將檔案列印為 PDF,我正在嘗試更改其中的一些資訊。例如,第一頁的標題和 PDF 檔案的名稱。如果有人知道如何在我的 R 閃亮代碼中做到這一點,請盡快告訴我。謝謝 :)
uj5u.com熱心網友回復:
將網頁列印為 pdf 檔案的對話框是瀏覽器的一項功能,不能使用 Shiny 直接操作。然而,瀏覽器使用來自 head 標簽的 HTML 元資料,例如列印標題。您可以將這些標簽添加到閃亮的網頁中:
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)

您可能還想添加shiny::tags$style標簽,例如添加@media規則以自定義列印布局,例如洗掉側邊欄或按鈕。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/364195.html
