将闪亮的仪表板下载为PDF后,为什么PDF中缺少量规图?

问题描述

我正在创建一个闪亮的仪表板。在这种情况下,用户将选择一个日期范围,并基于该日期范围量表进行更新。单击下载按钮后,我想将更新的图形下载为pdf报告。我可以通过单击下载按钮来下载pdf。但是在pdf文件中,量规图丢失了。我的代码如下创建仪表板:

library(dplyr)
library(shiny)
library(shinydashboard)
library(flexdashboard)
library(shinyjs)

js1 <- "
$(document).ready(function(){
  $('#print_btn').click(function () {
    domtoimage.toPng(document.getElementById('mainorder_CA'))
      .then(function (blob) {
        var pdf = new jsPDF('l','pt',[$('#mainorder_CA').width(),$('#mainorder_CA').height()]);
        pdf.addImage(blob,'PNG',$('#mainorder_CA').width(),$('#mainorder_CA').height());
        pdf.save('report');
      });
  });
});
"

date <- as.Date(c("2012-01-01","2012-01-02","2012-01-03","2012-01-04","2012-01-05","2012-01-06","2012-01-07","2012-01-08","2012-01-09","2012-01-10"))
a <- c(1,1,0)
b <- c(0,0)

df <-  data.frame(date,a,b)

ui <- dashboardPage(skin = 'purple',dashboardHeader(title = "Example"),dashboardSidebar(width = 300,daterangeInput("daterange","Please Choose Date",start = df[1,1],end = tail(df[,1)),tags$head(
                                       tags$script(src = "https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"),tags$script(src = "https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js"),tags$script(js1)
                                     ),actionButton("print_btn","Download")
                                     
                    ),dashboardBody(skin = 'purple',div(id = "mainorder_CA",fluidRow(
                                        tags$head(tags$style(css)),column(7,gaugeOutput("gauge1",width = "100px",height = "100px")),style='border-bottom:1px solid; padding: 20px;'
                                      ),gaugeOutput("gauge2",style='border-bottom:1px solid; padding: 20px;'
                                      )
                                  )
                    )
)

server <- function(input,output) {
  
  filteredData1 <- reactive({
    req(input$daterange)
    data = df[df$date >= input$daterange[1] & df$date <= input$daterange[2],]
    data1 = sum(data$a == 1)
    data1
    
  })
  
  filteredData2 <- reactive({
    req(input$daterange)
    data = df[df$date >= input$daterange[1] & df$date <= input$daterange[2],]
    data1 = sum(data$b == 1)
    data1
    
  })
  
  
  
  output$gauge1 <-  renderGauge({
    gauge(filteredData1(),min = 0,max = 10,sectors = gaugeSectors(success = c(9,10),warning = c(6,8 ),danger = c(0,5)),label = "Scr")
  })
  
  
  output$gauge2 <-  renderGauge({
    gauge(filteredData2(),label = "Scr")
  })
}

runApp(list(ui = ui,server = server),launch.browser = TRUE)

我不明白为什么缺少量规图?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)