如何解决将闪亮的仪表板下载为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 举报,一经查实,本站将立刻删除。