Skip to content

Commit 107ad49

Browse files
committed
bump version; update news/readme; onRender example
1 parent 5e5aded commit 107ad49

File tree

4 files changed

+61
-11
lines changed

4 files changed

+61
-11
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
22
Title: Create Interactive Web Graphics via Plotly's JavaScript Graphing Library
3-
Version: 3.2.0
3+
Version: 3.2.1
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "cpsievert1@gmail.com"),
66
person("Chris", "Parmer", role = c("aut", "cph"),

NEWS

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
3.2.0 -- 8 Mar 2015
1+
3.2.1 -- 10 Mar 2015
2+
3+
BUGFIX:
4+
5+
* Proper formatting for date tooltips.
6+
7+
3.2.0 -- 10 Mar 2015
28

39
CHANGES:
410

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ Or install the latest development version (on GitHub) via devtools:
1818
devtools::install_github("ropensci/plotly")
1919
```
2020

21-
## Introduction
21+
## Getting Started
2222

23-
If you use [ggplot2](http://cran.r-project.org/package=ggplot2), `ggplotly()` converts your plots to an interactive, web-based version! It also provide sensible tooltips that make it easier to decode values encoded as visual properties in the plot.
23+
### ggplot2 converter
24+
25+
If you use [ggplot2](http://cran.r-project.org/package=ggplot2), `ggplotly()` converts your plots to an interactive, web-based version! It also provides sensible tooltips, which can help us decode values encoded as visual properties in the plot.
2426

2527
```r
2628
library(plotly)
@@ -32,25 +34,33 @@ ggplotly(g)
3234

3335
![https://plot.ly/~cpsievert/9836](http://imgur.com/6G4zv7b)
3436

35-
TODO: mention event stuff
37+
If you'd like to see how `ggplotly()` does in converting different ggplot2 examples, we host a [plotly version](http://ropensci.github.io/plotly/) of the [official ggplot2 documentation](http://docs.ggplot2.org).
38+
39+
### plotly's custom R interface
3640

37-
__plotly__ also supports certain chart types that ggplot2 doesn't support (such as 3D [surface](https://plot.ly/r/3d-surface-plots/), [point](https://plot.ly/r/3d-scatter-plots/), and [line](https://plot.ly/r/3d-line-plots/) plots). You can easily create these (or any other plotly) charts using the high-level interface.
41+
__plotly__ supports some chart types that ggplot2 doesn't (such as 3D [surface](https://plot.ly/r/3d-surface-plots/), [point](https://plot.ly/r/3d-scatter-plots/), and [line](https://plot.ly/r/3d-line-plots/) plots). You can create these (or any other plotly) charts using the high-level interface.
3842

3943
```r
4044
plot_ly(z = volcano, type = "surface")
4145
```
4246

4347
![https://plot.ly/~brnvg/1134](https://plot.ly/~brnvg/1134.png)
4448

45-
The `ggplotly()` function converts a ggplot object to a plotly object, so if you like, you may 'post-process' your ggplot graphs to add custom plotly features, for example:
49+
For a more detailed overview of this interface, see [here](https://cran.r-project.org/web/packages/plotly/vignettes/intro.html)
4650

47-
```r
48-
layout(gg, hovermode = "closest")
49-
```
51+
### Hooking onto plotly events
52+
53+
[plotly.js](https://github.com/plotly/plotly.js) exposes a number of 'standard' events that work consistently across plot types. It's easy to hook into these events using the `event_data()` function in shiny apps, as these examples demonstrate:
54+
55+
1. [2D events](http://104.131.111.111:3838/plotlyEvents/) ([source](https://github.com/ropensci/plotly/tree/master/inst/examples/plotlyEvents))
56+
2. [Linked Clicks](http://104.131.111.111:3838/plotlyLinkedClick/) ([source](https://github.com/ropensci/plotly/tree/master/inst/examples/plotlyLinkedClick))
57+
3. [Linked Brush](http://104.131.111.111:3838/plotlyLinkedBrush/) ([source](https://github.com/ropensci/plotly/tree/master/inst/examples/plotlyLinkedBrush))
58+
59+
60+
You can also hook into these events without shiny using `htmlwidgets::onRender()` ([example](https://github.com/ropensci/plotly/tree/master/inst/examples/onRenderHover)). This, however, requires JavaScript knowledge and makes it much harder, if not impossible, to coordinate views between htmlwidgets.
5061

5162
## Documentation
5263

53-
* [An introduction to plotly's R API](https://cran.r-project.org/web/packages/plotly/vignettes/intro.html)
5464
* Examples and vignettes on plotly's R homepage - <https://plot.ly/r>
5565
* The complete figure reference guide - <https://plot.ly/r/reference>
5666

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: "Using plotly with onRender"
3+
author: "Carson Sievert"
4+
date: "`r Sys.Date()`"
5+
output: html_document
6+
---
7+
8+
```{r, message = FALSE, warning = FALSE}
9+
library(plotly)
10+
library(htmlwidgets)
11+
plot_ly(x = 1:10, y = rnorm(10), marker = list(color = rep("black", 10))) %>%
12+
as.widget() %>%
13+
onRender('
14+
function(el, x) {
15+
var graphDiv = document.getElementById(el.id);
16+
// color this point red on hover
17+
el.on("plotly_hover", function(data) {
18+
var trace = data.points[0].curveNumber;
19+
var pt = data.points[0].pointNumber;
20+
var marker = x.data[trace].marker;
21+
marker.color[pt] = "red";
22+
Plotly.restyle(graphDiv, marker, trace)
23+
})
24+
// color this point black on unhover
25+
el.on("plotly_unhover", function(data) {
26+
var trace = data.points[0].curveNumber;
27+
var pt = data.points[0].pointNumber;
28+
var marker = x.data[trace].marker;
29+
marker.color[pt] = "black";
30+
Plotly.restyle(graphDiv, marker, trace)
31+
})
32+
}
33+
')
34+
```

0 commit comments

Comments
 (0)