diff --git a/_posts/r/chart-events/2019-09-12-r-chart-events-index.md b/_posts/r/chart-events/2019-09-12-r-chart-events-index.md index 958add23c48d..fdf03340f1a4 100644 --- a/_posts/r/chart-events/2019-09-12-r-chart-events-index.md +++ b/_posts/r/chart-events/2019-09-12-r-chart-events-index.md @@ -1,28 +1,4 @@ --- permalink: r/chart-events/ -description: All Plotly charts have click, hover and zoom events exposed to add custom controls with Plotly's JavaScript -name: More Chart Events -layout: langindex -language: r -display_as: chart_events -thumbnail: thumbnail/mixed.jpg -page_type: example_index -order: 20 +redirect_to: https://dashr.plot.ly --- - - -
-
- -
-
-
-

Plotly R Library Chart Events

-

{{page.description}}postMessageAPI.

-
-
-
-
- - {% assign languagelist = site.posts | where:"language","r" | where:"display_as","chart_events" | where: "layout","base" | sort: "order" %} - {% include posts/documentation_eg.html %} diff --git a/_posts/r/chart-events/callbacks-click/2015-04-09-click.html b/_posts/r/chart-events/callbacks-click/2015-04-09-click.html deleted file mode 100755 index efb57eabb694..000000000000 --- a/_posts/r/chart-events/callbacks-click/2015-04-09-click.html +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: Binding to Click Events -plot_url: https://codepen.io/plotly/embed/BNEVLx/?height=770&theme-id=15263&default-tab=result -height: 750 -language: r -suite: click-events -sitemap: false -arrangement: horizontal -order: 0 ---- - -plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species) diff --git a/_posts/r/chart-events/callbacks-click/2015-04-09-click_index.html b/_posts/r/chart-events/callbacks-click/2015-04-09-click_index.html index 5e7567de43c5..a96510ff770c 100755 --- a/_posts/r/chart-events/callbacks-click/2015-04-09-click_index.html +++ b/_posts/r/chart-events/callbacks-click/2015-04-09-click_index.html @@ -1,13 +1,5 @@ --- -name: Click Events with JavaScript permalink: r/click-events/ -description: How to bind callback functions to click events in R charts with JavaScript. -layout: base -thumbnail: thumbnail/click.jpg -language: r -page_type: example_index -display_as: chart_events -order: 4 +redirect_to: https://dashr.plot.ly --- -{% assign examples = site.posts | where:"language","r" | where:"suite","click-events" | sort: "order" %} -{% include posts/auto_examples.html examples=examples %} + diff --git a/_posts/r/chart-events/callbacks-dropdowns/2015-04-09-dropdown.html b/_posts/r/chart-events/callbacks-dropdowns/2015-04-09-dropdown.html deleted file mode 100755 index 4aa491da8aeb..000000000000 --- a/_posts/r/chart-events/callbacks-dropdowns/2015-04-09-dropdown.html +++ /dev/null @@ -1,28 +0,0 @@ ---- -name: Binding to Dropdown Events -plot_url: https://codepen.io/plotly/embed/WvWLWJ/?height=725&theme-id=15263&default-tab=result -height: 800 -language: r -suite: dropdown-events -arrangement: horizontal -sitemap: false -order: 0 ---- - -df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv') - -# light grey boundaries -l <- list(color = toRGB("grey"), width = 0.5) - -# specify map projection/options -g <- list( - showframe = FALSE, - showcoastlines = FALSE, - projection = list(type = 'Mercator') -) - -plot_ly(df, z = ~GDP..BILLIONS., text = ~COUNTRY, locations = ~CODE, type = 'choropleth', - color = ~GDP..BILLIONS., colors = 'Blues', marker = list(line = l), - colorbar = list(tickprefix = '$', title = 'GDP Billions US$')) %>% - layout(title = '2014 Global GDP
Source:CIA World Factbook', - geo = g) diff --git a/_posts/r/chart-events/callbacks-hover/2015-04-09-hover_index.html b/_posts/r/chart-events/callbacks-hover/2015-04-09-hover_index.html index 26681a94ecfb..2b34dfbc844d 100755 --- a/_posts/r/chart-events/callbacks-hover/2015-04-09-hover_index.html +++ b/_posts/r/chart-events/callbacks-hover/2015-04-09-hover_index.html @@ -1,13 +1,4 @@ --- -name: Hover Events with JavaScript permalink: r/hover-events/ -description: How to add custom hover effects to Python charts with JavaScript. -layout: base -thumbnail: thumbnail/hover.jpg -language: r -page_type: example_index -display_as: chart_events -order: 5 +redirect_to: https://dashr.plot.ly --- -{% assign examples = site.posts | where:"language","r" | where:"suite","hover-events" | sort: "order" %} -{% include posts/auto_examples.html examples=examples %} diff --git a/_posts/r/chart-events/callbacks-zoom/2015-04-09-zoom-bind.html b/_posts/r/chart-events/callbacks-zoom/2015-04-09-zoom-bind.html deleted file mode 100755 index 82e36ad87d38..000000000000 --- a/_posts/r/chart-events/callbacks-zoom/2015-04-09-zoom-bind.html +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: Binding to Zoom Events -plot_url: https://codepen.io/plotly/embed/PqgLmv/?height=600&theme-id=15263&default-tab=result -height: 650 -language: r -arrangement: horizontal -suite: zoom-events -sitemap: false -order: 4 ---- - -plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species, colors = "Set1") diff --git a/_posts/r/chart-events/callbacks-zoom/2015-04-09-zoom_index.html b/_posts/r/chart-events/callbacks-zoom/2015-04-09-zoom_index.html index 5423c1faedd0..31b32cd97b5d 100755 --- a/_posts/r/chart-events/callbacks-zoom/2015-04-09-zoom_index.html +++ b/_posts/r/chart-events/callbacks-zoom/2015-04-09-zoom_index.html @@ -1,13 +1,4 @@ --- -name: Adding Zoom Effects with JavaScript permalink: r/zoom-events/ -description: How to bind callback functions to zoom events in JavaScript charts. -layout: base -thumbnail: thumbnail/zoom.jpg -language: r -page_type: example_index -display_as: chart_events -order: 4 +redirect_to: https://dashr.plot.ly --- -{% assign examples = site.posts | where:"language","r" | where:"suite","zoom-events" | sort: "order" %} -{% include posts/auto_examples.html examples=examples %} diff --git a/_posts/r/streaming/2017-07-17-streaming.Rmd b/_posts/r/streaming/2017-07-17-streaming.Rmd deleted file mode 100644 index ed1b57380781..000000000000 --- a/_posts/r/streaming/2017-07-17-streaming.Rmd +++ /dev/null @@ -1,274 +0,0 @@ ---- -name: Streaming -permalink: r/streaming/ -description: Getting Started with Streaming in R -layout: base -thumbnail: thumbnail/streaming-thumb-square.gif -language: r -page_type: example_index -display_as: streaming -order: 1 -output: - html_document: - keep_md: true ---- - -```{r, echo = FALSE, message=FALSE} -knitr::opts_chunk$set(eval = FALSE) -``` -### New to Plotly? - -Plotly's R library is free and open source!
-[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).
-You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.
-We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started! - -### Version Check - -Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!
-Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version. -```{r} -library(plotly) -packageVersion('plotly') -``` - -### Streaming in R - -The `plotlyProxy` and `plotlyProxyInvoke` functions allow a plotly object to be modified by invoking any of the [PlotlyJS methods](https://plot.ly/javascript/plotlyjs-function-reference). In particular, the `extendTraces` function allows you to add data to traces in an exisiting plotly object. See below application for code. - - - -### Basic Example - -```{r} -library(shiny) -library(plotly) - -rand <- function() { - runif(1, min=1, max=9) -} - -ui <- fluidPage( - includeCSS("styles.css"), - - headerPanel(h1("Streaming in Plotly", align = "center")), - br(), - div(actionButton("button", "Extend Trace"), align = "center"), - br(), - div(plotlyOutput("plot"), id='graph') -) - -server <- function(input, output, session) { - - p <- plot_ly( - y = c(rand(),rand(),rand()), - type = 'scatter', - mode = 'lines', - line = list( - color = '#25FEFD', - width = 3 - ) - ) %>% - layout( - yaxis = list(range = c(0,10)) - ) - - output$plot <- renderPlotly(p) - - observeEvent(input$button, { - while(TRUE){ - Sys.sleep(1) - plotlyProxy("plot", session) %>% - plotlyProxyInvoke("extendTraces", list(y=list(list(rand()))), list(0)) - } - }) -} - -shinyApp(ui, server) -``` - -### Multiple Traces - -```{r} -library(shiny) -library(plotly) - -rand <- function() { - runif(1, min=1, max=9) -} - -ui <- fluidPage( - includeCSS("styles.css"), - - headerPanel(h1("Streaming in Plotly: Multiple Traces", align = "center")), - br(), - div(actionButton("button", "Extend Traces"), align = "center"), - br(), - div(plotlyOutput("plot"), id='graph') -) - -server <- function(input, output, session) { - - p <- plot_ly( - type = 'scatter', - mode = 'lines' - ) %>% - add_trace( - y = c(rand(),rand(),rand()), - line = list( - color = '#25FEFD', - width = 3 - ) - ) %>% - add_trace( - y = c(rand(),rand(),rand()), - line = list( - color = '#636EFA', - width = 3 - ) - ) %>% - layout( - yaxis = list(range = c(0,10)) - ) - - output$plot <- renderPlotly(p) - - observeEvent(input$button, { - while(TRUE){ - Sys.sleep(1) - plotlyProxy("plot", session) %>% - plotlyProxyInvoke("extendTraces", list(y=list(list(rand()), list(rand()))), list(1,2)) - } - }) - -} - -shinyApp(ui, server) -``` - -### Timestamp - -```{r} -library(shiny) -library(plotly) - -rand <- function() { - runif(1, min=1, max=9) -} - -t <- format(Sys.time(), "%H:%M:%S") - -ui <- fluidPage( - includeCSS("styles.css"), - - headerPanel(h1("Streaming in Plotly: Timestamp", align = "center")), - br(), - div(actionButton("button", "Extend Trace"), align = "center"), - br(), - div(plotlyOutput("plot"), id='graph') -) - -server <- function(input, output, session) { - - p <- plot_ly( - x = t, - y = rand(), - type = 'scatter', - mode = 'lines', - line = list( - color = '#25FEFD', - width = 3 - ) - ) %>% - layout( - yaxis = list(range = c(0,10)) - ) - - output$plot <- renderPlotly(p) - - observeEvent(input$button, { - while(TRUE){ - Sys.sleep(1) - t <- format(Sys.time(), "%H:%M:%S") - plotlyProxy("plot", session) %>% - plotlyProxyInvoke("extendTraces", list(x=list(list(t)), y=list(list(rand()))), list(0)) - } - }) - -} - -shinyApp(ui, server) -``` - -### Subplots - -```{r} -library(shiny) -library(plotly) - -rand <- function() { - runif(1, min=1, max=9) -} - -ui <- fluidPage( - includeCSS("styles.css"), - - headerPanel(h1("Streaming in Plotly: Subplots", align = "center")), - br(), - div(actionButton("button", "Extend Traces"), align = "center"), - br(), - div(plotlyOutput("plot"), id='graph') -) - -server <- function(input, output, session) { - - p <- plot_ly( - y = c(rand(),rand(),rand()), - type = 'scatter', - mode = 'lines', - line = list( - color = '#25FEFD', - width = 3 - ) - ) %>% - layout( - yaxis = list(range = c(0,10)) - ) - - pp <- plot_ly( - y = c(rand(),rand(),rand()), - type = 'scatter', - mode = 'lines', - line = list( - color = '#636EFA', - width = 3 - ) - ) %>% - layout( - yaxis = list(range = c(0,10)) - ) - - s <- subplot(p,pp, nrows = 2) - - output$plot <- renderPlotly(s) - - observeEvent(input$button, { - while(TRUE){ - Sys.sleep(1) - plotlyProxy("plot", session) %>% - plotlyProxyInvoke("extendTraces", list(y=list(list(rand()), list(rand()))), list(0,1)) - } - }) - -} - -shinyApp(ui, server) -``` - -### Reference - -[Click here](https://plot.ly/javascript/plotlyjs-function-reference) to visit the PlotlyJS functions. - -```{r} -?plotlyProxy -``` diff --git a/_posts/r/streaming/2017-07-17-streaming.md b/_posts/r/streaming/2017-07-17-streaming.md index f4b4ab3dec6d..7d199dca13bd 100644 --- a/_posts/r/streaming/2017-07-17-streaming.md +++ b/_posts/r/streaming/2017-07-17-streaming.md @@ -1,278 +1,4 @@ --- -name: Streaming permalink: r/streaming/ -description: Getting Started with Streaming in R -layout: base -thumbnail: thumbnail/streaming-thumb-square.gif -language: r -page_type: example_index -display_as: streaming -order: 1 -output: - html_document: - keep_md: true +redirect_to: https://dashr.plot.ly --- - - -### New to Plotly? - -Plotly's R library is free and open source!
-[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).
-You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.
-We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started! - -### Version Check - -Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!
-Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version. - -```r -library(plotly) -packageVersion('plotly') -``` - -### Streaming in R - -The `plotlyProxy` and `plotlyProxyInvoke` functions allow a plotly object to be modified by invoking any of the [PlotlyJS methods](https://plot.ly/javascript/plotlyjs-function-reference). In particular, the `extendTraces` function allows you to add data to traces in an exisiting plotly object. See below application for code. - - - -### Basic Example - - -```r -library(shiny) -library(plotly) - -rand <- function() { - runif(1, min=1, max=9) -} - -ui <- fluidPage( - includeCSS("styles.css"), - - headerPanel(h1("Streaming in Plotly", align = "center")), - br(), - div(actionButton("button", "Extend Trace"), align = "center"), - br(), - div(plotlyOutput("plot"), id='graph') -) - -server <- function(input, output, session) { - - p <- plot_ly( - y = c(rand(),rand(),rand()), - type = 'scatter', - mode = 'lines', - line = list( - color = '#25FEFD', - width = 3 - ) - ) %>% - layout( - yaxis = list(range = c(0,10)) - ) - - output$plot <- renderPlotly(p) - - observeEvent(input$button, { - while(TRUE){ - Sys.sleep(1) - plotlyProxy("plot", session) %>% - plotlyProxyInvoke("extendTraces", list(y=list(list(rand()))), list(0)) - } - }) -} - -shinyApp(ui, server) -``` - -### Multiple Traces - - -```r -library(shiny) -library(plotly) - -rand <- function() { - runif(1, min=1, max=9) -} - -ui <- fluidPage( - includeCSS("styles.css"), - - headerPanel(h1("Streaming in Plotly: Multiple Traces", align = "center")), - br(), - div(actionButton("button", "Extend Traces"), align = "center"), - br(), - div(plotlyOutput("plot"), id='graph') -) - -server <- function(input, output, session) { - - p <- plot_ly( - type = 'scatter', - mode = 'lines' - ) %>% - add_trace( - y = c(rand(),rand(),rand()), - line = list( - color = '#25FEFD', - width = 3 - ) - ) %>% - add_trace( - y = c(rand(),rand(),rand()), - line = list( - color = '#636EFA', - width = 3 - ) - ) %>% - layout( - yaxis = list(range = c(0,10)) - ) - - output$plot <- renderPlotly(p) - - observeEvent(input$button, { - while(TRUE){ - Sys.sleep(1) - plotlyProxy("plot", session) %>% - plotlyProxyInvoke("extendTraces", list(y=list(list(rand()), list(rand()))), list(1,2)) - } - }) - -} - -shinyApp(ui, server) -``` - -### Timestamp - - -```r -library(shiny) -library(plotly) - -rand <- function() { - runif(1, min=1, max=9) -} - -t <- format(Sys.time(), "%H:%M:%S") - -ui <- fluidPage( - includeCSS("styles.css"), - - headerPanel(h1("Streaming in Plotly: Timestamp", align = "center")), - br(), - div(actionButton("button", "Extend Trace"), align = "center"), - br(), - div(plotlyOutput("plot"), id='graph') -) - -server <- function(input, output, session) { - - p <- plot_ly( - x = t, - y = rand(), - type = 'scatter', - mode = 'lines', - line = list( - color = '#25FEFD', - width = 3 - ) - ) %>% - layout( - yaxis = list(range = c(0,10)) - ) - - output$plot <- renderPlotly(p) - - observeEvent(input$button, { - while(TRUE){ - Sys.sleep(1) - t <- format(Sys.time(), "%H:%M:%S") - plotlyProxy("plot", session) %>% - plotlyProxyInvoke("extendTraces", list(x=list(list(t)), y=list(list(rand()))), list(0)) - } - }) - -} - -shinyApp(ui, server) -``` - -### Subplots - - -```r -library(shiny) -library(plotly) - -rand <- function() { - runif(1, min=1, max=9) -} - -ui <- fluidPage( - includeCSS("styles.css"), - - headerPanel(h1("Streaming in Plotly: Subplots", align = "center")), - br(), - div(actionButton("button", "Extend Traces"), align = "center"), - br(), - div(plotlyOutput("plot"), id='graph') -) - -server <- function(input, output, session) { - - p <- plot_ly( - y = c(rand(),rand(),rand()), - type = 'scatter', - mode = 'lines', - line = list( - color = '#25FEFD', - width = 3 - ) - ) %>% - layout( - yaxis = list(range = c(0,10)) - ) - - pp <- plot_ly( - y = c(rand(),rand(),rand()), - type = 'scatter', - mode = 'lines', - line = list( - color = '#636EFA', - width = 3 - ) - ) %>% - layout( - yaxis = list(range = c(0,10)) - ) - - s <- subplot(p,pp, nrows = 2) - - output$plot <- renderPlotly(s) - - observeEvent(input$button, { - while(TRUE){ - Sys.sleep(1) - plotlyProxy("plot", session) %>% - plotlyProxyInvoke("extendTraces", list(y=list(list(rand()), list(rand()))), list(0,1)) - } - }) - -} - -shinyApp(ui, server) -``` - -### Reference - -[Click here](https://plot.ly/javascript/plotlyjs-function-reference) to visit the PlotlyJS functions. - - -```r -?plotlyProxy -```