Last active
August 8, 2017 04:26
-
-
Save aagarw30/d227e0131c2d81f47496fb1476699df8 to your computer and use it in GitHub Desktop.
Plotly, Dygraphs and R Shiny, save as png
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Title: Experiment with plotly and dygraphs and save the output plot. Used export() function. | |
Description: Experiment with plotly and dygraphs and save the output plot. Used export() function to save the plot. | |
License: GPL-3 | |
Author: Abhinav Agrawal | |
DisplayMode: Showcase | |
Tags: R, R Shiny | |
Type: Shiny |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(plotly) | |
library(dygraphs) | |
path <- getwd() | |
setwd(path) | |
shinyServer(function(input, output, session) { | |
output$plot_plotly <- renderPlotly({ | |
p <- plot_ly(x = c(1,2,3,4), y = c(2,4,1,3), type = 'scatter', mode = 'lines') | |
export(p, file = "plotlyplot.png") | |
return(p) | |
}) | |
output$plot_dy <- renderDygraph({ | |
lungDeaths <- cbind(mdeaths, fdeaths) | |
q <- dygraph(lungDeaths) | |
export(q, file = "dygraph.png") | |
return(q) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(plotly) | |
library(dygraphs) | |
shinyUI( | |
fluidPage( | |
titlePanel("Plotly, Dygraphs and R Shiny, save as png"), | |
sidebarLayout( | |
sidebarPanel(), | |
mainPanel( | |
plotlyOutput("plot_plotly"), | |
dygraphOutput("plot_dy") | |
) | |
) | |
) | |
) |
I ran the code like
library(shiny)
library(plotly)
library(dygraphs)
library(htmlwidgets)
path <- getwd()
setwd(path)
ui<-shinyUI(
fluidPage(
titlePanel("Plotly, Dygraphs and R Shiny, save as png"),
sidebarLayout(
sidebarPanel(),
mainPanel(
plotlyOutput("plot_plotly"),
dygraphOutput("plot_dy")
)
)
)
)
server<-shinyServer(function(input, output, session) {
output$plot_plotly <- renderPlotly({
p <- plot_ly(x = c(1,2,3,4), y = c(2,4,1,3), type = 'scatter', mode = 'lines')
export(p, file = "plotlyplot.png")
return(p)
})
output$plot_dy <- renderDygraph({
lungDeaths <- cbind(mdeaths, fdeaths)
q <- dygraph(lungDeaths)
export(q, file = "dygraph.png")
return(q)
})
})
shinyApp(ui,server)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ran the Code but it doesn't work it gives me an error saying
no applicable method for 'plotly_build' applied to an object of class "c('dygraphs', 'htmlwidget')"
What should I do now. Please let me know...