打印闪亮的仪表板页面会更改每个对象的实际位置

时间:2018-12-14 00:48:06

标签: r shiny

我有一个简单的闪亮仪表板,尝试使用页面底部的操作按钮“ PRINT”进行打印。问题是,正如您将看到的,由于仪表板对象位置错误,生成的页面已“损坏”。在浏览器模式下,情况变得更糟。为什么会发生这种情况?这种情况是,当我最初运行该应用程序(在最小化的窗口中)并单击“打印”时,页面看起来很好。

enter image description here

#ui.r
library(shiny)
library(shinydashboard)
library(shinyjs)
library(plotly)
library(leaflet)
library(scales)
library(tidyverse)
library(reshape2)
library(V8)
library(maps)
jsCode <- 'shinyjs.winprint = function(){
window.print();
}'

ui <- dashboardPage(
  dashboardHeader(
    title = "[School Name] Enrollment Projections for Fall 2019",
    titleWidth = 500
  ),
  dashboardSidebar(),
  dashboardBody(
    useShinyjs(),
    fluidRow(
      column(10,
             plotlyOutput("plot",height=375)),
      box(background = "light-blue",
          height = 375,width = 2
          )),
    fluidRow(
      box(background = "light-blue",
          height = 375,width = 2),
      column(10,
             leafletOutput("mymap",height=375))
          ),
    fluidRow(
      box(height = 130,width = 12)
    ),
    useShinyjs(),
    extendShinyjs(text = jsCode),
    actionButton("print", "PRINT")

          )
          )
#server.r
library(shiny)
library(shinydashboard)
library(shinyjs)
library(plotly)
library(leaflet)
library(scales)
library(tidyverse)
library(reshape2)
library(maps)
server <- shinyServer(function(input, output, session) {
  addClass(selector = "body", class = "sidebar-collapse")

  observeEvent(input$print, {
    js$winprint()
  })


  output$plot<-renderPlotly({
    today <- Sys.Date()
    tm <- seq(0, 600, by = 10)
    x <- today - tm
    y <- rnorm(length(x))
    p <- plot_ly(x = ~x, y = ~y, mode = 'lines', text = paste(tm, "days from today"))

  })

  output$mymap <- renderLeaflet({
    library(maps)
    mapStates = map("state", fill = TRUE, plot = FALSE)
    leaflet(data = mapStates) %>% addTiles() %>%
      addPolygons(fillColor = topo.colors(10, alpha = NULL), stroke = FALSE)


  })

})

0 个答案:

没有答案