r - Download ggvis plot from reactive set -


i have shiny app allows user choose plot on x , y axis based on loaded data frame. trying allow user download current plot view. opening launching app in google chrome because know not work save file if app launched within r studio. of saves png file, blank.

screenshot of app ui can seen here

i have used these posts try resolve issue:

downloading png shiny (r)

downloading png shiny (r) pt. 2

the app not work if vis() changed function rather reactive. however, when filtereddata() changed reactive function, app still works same. however, blank png still yield if within downloadhandler(... have vis(), filtereddata() or print(filtereddata()). if print(vis()) used, window pops in browser says "key / in use". minimal working code replicates issue below , can provide appreciated.

#check packages use in library library('shiny') #allows shiny app used library('stringr') #string opperator library('ggvis') #allows interactive ploting library('dplyr')  alldata <- iris  #establish options drop down menus specieschoices <- unique(as.character(alldata$species)) petalwchoices <- unique(as.character(alldata$petal.width)) petallchoices <- unique(as.character(alldata$petal.length)) sepallchoices <- unique(as.character(alldata$sepal.length)) sepalwchoices <- unique(as.character(alldata$sepal.width))  # ui  ui<-fluidpage( titlepanel("explorer"), fluidrow( column(4,        wellpanel(          h4("apply filters"),          selectinput(inputid = "species", label="select species:", choices = sort(specieschoices), selected="setosa", multiple = true, selectize = true),          selectinput(inputid = "petalw", label="select petal width:", choices = sort(petalwchoices), selected=petalwchoices, multiple = true, selectize = false),          selectinput(inputid = "petall", label="select petal length", choices = sort(petallchoices), selected=petallchoices, multiple = true, selectize = false),          selectinput(inputid = "sepall", label="select sepal length", choices = sort(sepallchoices), selected=sepallchoices, multiple = true, selectize = false),          selectinput(inputid = "sepalw", label="select sepal width", choices = sort(sepalwchoices), selected=sepalwchoices, multiple = true, selectize = false),          downloadbutton('downloadplot', 'download plot')          )), column(8,        ggvisoutput("plot1") ), column(4,        wellpanel(          h4("data variables"),          selectinput(inputid = "x", label="select x-axis variable:", choices=as.character(names(alldata[,1:4])),selected='petal.length', multiple = false),          selectinput(inputid = "y", label="select y-axis variable:", choices=as.character(names(alldata[,1:4])),selected='petal.width', multiple = false)        )) ))  #server server<-function(input,output,session) {  #set reactive variables filtereddata <- reactive({  # apply filters m <- alldata %>% filter(   `species` %in% input$species,   `petal.width` %in% input$petalw,   `petal.length` %in% input$petall,   `sepal.width` %in% input$sepalw,   `sepal.length` %in% input$sepall ) m <- droplevels(as.data.frame(m)) m })  vis <- reactive({  xvar <- prop("x", as.symbol(input$x)) yvar <- prop("y", as.symbol(input$y))  p1 = filtereddata() %>%   ggvis(x = xvar, y = yvar) %>%   layer_points(size.hover := 200,                fillopacity:= 0.5, fillopacity.hover := 1,                fill = ~species   )  })  #actually plots data vis %>% bind_shiny("plot1")  ################# part need with##################### output$downloadplot <- downloadhandler(   filename = paste0(input$y, '_vs_', input$x, "_", sys.date(), ".png"),   content = function(file) {     png(file)     vis()     dev.off()   },   contenttype = 'image/png' ) ############################################################################## }  #run shiny app display webpage shinyapp(ui=ui, server=server) 

i solved issue creating function created ggplot plot exact replicate of ggvis plot use downloadhandler.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -