r - save custom ggplotly plot to pdf (in Shiny) -


i export ggplotly plot in shiny in format of pdf. can plotly::exportand shiny::downloadhandler function have need: save kind of ggplotly plot user can customize inside app (for example zooming on or filter of elements, etc.).

here example:

library(webshot) library(htmlwidgets) library(raster) library(ggplot2) library(shiny) library(plotly)  server <- function(input, output, session) {       #plot function     target_plot <- reactive({         dsamp <- diamonds[sample(nrow(diamonds), 1000), ]         p <- qplot(carat, price, data=dsamp, colour=clarity)          ggplotly(p)     })      output$plot_display <- renderplotly({         target_plot()     })      #export function       output$plot_export <- downloadhandler("test.pdf", function(thefile) {        makepdf <- function(filename){         pdf(file = filename)          export(target_plot(), file = "test.png")          r <- brick(file.path(getwd(), "test.png"))         plotrgb(r)          dev.off()       }        makepdf(thefile)     }) }  #### user interface ui <- fluidpage(    sidebarlayout(      sidebarpanel(         downloadbutton("plot_export", label = "download")     ),      mainpanel(         plotlyoutput("plot_display", height = "550px")     )   ) )  shinyapp(ui = ui, server = server) 

unfortunately solution produces same pdf file. not care possible user modifications in shiny app. example if hide of elements except "vvs1" export remains same.

app:

enter image description here

export file:

enter image description here

i know there easy bulit in function (in modebar) in plotly export plots need solution works in r pdf() function, because create report many different plots.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -