Экспортируйте графики, созданные только пакетом rpivotTable в RShiny

#r #shiny #pivot-table

#r #блестящий #сводный стол

Вопрос:

Я новичок в Ршины. Я использую пакет rpivotTable и успешно создал сводную таблицу. Я также могу загрузить таблицу в виде файла excel и csv. Как я могу экспортировать только графики (в формате pdf и png), созданные в этом пакете? Это мой код, который создает и экспортирует сводную таблицу:

Любая помощь будет очень признательна!

 library(shiny) library(shinydashboard) library(tidyverse) library(readxl) library(DT) library(rpivotTable) library(shinyBS) library(rvest) library(htmlwidgets) library(shinyjs) library(clipr) library(writexl)   df lt;- ##read your data here  #ui ui = fluidPage(  titlePanel("put your title here"),    radioButtons(inputId = "format", label = "Enter the format to download",   choices = c( "csv", "excel"), inline = FALSE, selected = "csv"),  downloadButton("download_pivot"),  actionButton("copy_pivot", "Copy"),  fluidRow(rpivotTableOutput("RPivot",width = "100%", height = "1000px"))  )   #server server lt;- function(input, output) {   df0 lt;- df      output$RPivot lt;- renderRpivotTable(  rpivotTable(df0,  rendererName = "Table", width="50%", height="550px",  onRefresh = htmlwidgets::JS(  "function(config) {  Shiny.onInputChange('RPivot', document.getElementById('RPivot').innerHTML);   }"))  )      # create an eventReactive dataframe that regenerates anytime the pivot object changes # wrapped in a tryCatch to only return table object. errors out when charts are shown  pivot_tbl lt;- eventReactive(input$RPivot, {  tryCatch({  input$RPivot %gt;%  read_html %gt;%  html_table(fill = TRUE) %gt;%  .[[2]]  }, error = function(e) {  return()  })  })   # allow the user to download once the pivot_tbl object is available  observe({  if (is.data.frame(pivot_tbl()) amp;amp; nrow(pivot_tbl()) gt; 0) {  shinyjs::enable("download_pivot")  shinyjs::enable("copy_pivot")  } else {  shinyjs::disable("download_pivot")  shinyjs::disable("copy_pivot")  }  })     # using shiny's download handler to get the data output  output$download_pivot lt;- downloadHandler(  filename = function() {  if (input$format == "csv") {  "pivot.csv"  } else if (input$format == "excel") {  "pivot.xlsx"  }  },  content = function(file) {  if (input$format == "csv") {  write_csv(pivot_tbl(), path = file)  } else if (input$format == "excel") {  writexl::write_xlsx(pivot_tbl(), path = file)  }  }  )   # copy pivot table - works natively on Windows/OSX. Requires xclip on Linux  observeEvent(input$copy_pivot, {  clipr::write_clip(pivot_tbl(), object_type = "table")  })      }  # Run the application  shinyApp(ui = ui, server = server)