如何在url上以pdf格式下载

时间:2018-07-05 12:33:32

标签: r shiny r-markdown

  

我想将闪亮的应用程序导出到url上传的pdf模板中,我不知道怎么做,并且没有得到任何aaporach且闪亮   我尝试在加载网址时调用按钮的代码

实际上,我希望整个发光的应用程序在加载时自动以pdf格式下载,实际上我想在应用程序内部提取数据

server.r

library(RJDBC)
library(dplyr)
library(shiny) 
library(ggplot2)
library(gridExtra)
library(DT)
dsn_driver = "com.ibm.db2.jcc.DB2Driver"
dsn_database = "BLUDB"            # e.g. "BLUDB"
dsn_hostname = "awh-yp-small03.services.dal.bluemix.net" # e.g.: "awh-yp-small03.services.dal.bluemix.net"
dsn_port = ""                # e.g. "50000"
dsn_protocol = ""            # i.e. "TCPIP"
dsn_uid = "        # e.g. ""
dsn_pwd = ""
jcc = JDBC("com.ibm.db2.jcc.DB2Driver", "db2jcc4.jar");
jdbc_path = paste("jdbc:db2://",  dsn_hostname, ":", dsn_port, "/", dsn_database, sep="");
conn = dbConnect(jcc, jdbc_path, user=dsn_uid, password=dsn_pwd)
shinyServer(function(input, output) {
  ## vals will contain all plot and table grobs

  vals <- reactiveValues(p1=NULL,p2=NULL,t1=NULL)
this is the data frame as  an example i am using write now 
  cipltdprodstorewise = data.frame(
    Strr=c("str1","str2","str3"),
    Product= c("prod1","prod2","prod3"),
    TOTAL=c("total1","total2","total3"),
    stringsAsFactors = FALSE
  )

  output$t1=renderTable(

     cipltdprodstorewise


  )

  output$export = downloadHandler(
    filename = function() {"cip.pdf"},
    content = function(file) {
      pdf(file,onefile = TRUE)
      grid.arrange(vals$p1,vals$p2,vals$t1) 
      dev.off()
    }
  )

})

ui.r

library(shiny)
jscode <- "
shinyjs.init = function() {
  $(document).keypress(function(e) { alert('Key pressed: ' + e.which); });
}"
shinyUI(fluidPage(

  # Application title
  titlePanel("Today Cipla Sales On 99RS Platform"),
  sidebarLayout(
    sidebarPanel(
      downloadButton('export')
    ),
  # Sidebar with a slider input for number of bins

    # Show a plot of the generated distribution
    mainPanel(

      tableOutput("t1")
    )

)))

0 个答案:

没有答案