r - GGPlotly: downloadHandler giving empty plot -


i having difficulties plotly. able download plotly pdf. while adding code x , y axis parameters (cause if transfer ggplot plotly, titles of x , y axis cut)

this code working download pdf file:

library(shiny) library(dt) library(ggplot2) library(plotly)   shinyapp(   ui = fluidpage(     fluidrow(downloadbutton('downloadplot',label='download plot')),     plotlyoutput('plot1')   ),   server = function(input, output) {      testplot <- function(){  <- ggplot(mtcars, aes(x = interaction(cyl, carb, lex.order = t), y = mpg,fill = interaction(cyl, carb, lex.order = t))) +    geom_boxplot()      }      output$plot1 <- renderplotly({testplot()})      output$downloadplot <- downloadhandler(       filename ="plot.pdf",       content = function(file) {         pdf(file, width=12, height=6.3)         print(testplot())         dev.off()       })}) 

and addition of code fix titles of ggplotly fails:

a <- ggplot(mtcars, aes(x = interaction(cyl, carb, lex.order = t), y = mpg,fill = interaction(cyl, carb, lex.order = t))) +    geom_boxplot()  p <- ggplotly(a + ylab(" ") + xlab(" "))  x <- list(   title = "[x]" ) y <- list(   title = "[y]" ) p %>% layout(xaxis = x, yaxis = y)} 

gives empty plot...

thanks help!

i have solved question. solution not elegant works!

so trick set x , y titles in renderplotly , not in testplot() function.

however x , y axis titles have additionally typed in testplot() function - cause going our output pdf, , view of plot done plotly.

here code:

library(shiny) library(dt) library(ggplot2) library(plotly)   shinyapp(   ui = fluidpage(     fluidrow(downloadbutton('downloadplot',label='download plot')),     plotlyoutput('plot1')   ),   server = function(input, output) {      testplot <- function(){        <- ggplot(mtcars, aes(x = interaction(cyl, carb, lex.order = t), y = mpg,fill = interaction(cyl, carb, lex.order = t))) +          geom_boxplot()      }      output$plot1 <- renderplotly({        p <- ggplotly(testplot() + ylab(" ") + xlab(" "))        x <- list(         title = "[x]"       )       y <- list(         title = "[y]"       )       p %>% layout(xaxis = x, yaxis = y)})      output$downloadplot <- downloadhandler(       filename ="plot.pdf",       content = function(file) {         pdf(file, width=12, height=6.3)         print(testplot())         dev.off()       })}) 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -