Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb9296f

Browse files
committed
start r dropdown doc
1 parent 55c363e commit cb9296f

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

_posts/r/2016-08-10-dropdowns.Rmd

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: Adding Dropdowns with JavaScript | Examples | Plotly
3+
name: Dropdown Events
4+
permalink:
5+
description: How to add dropdowns to Python charts with JavaScript.
6+
layout: base
7+
thumbnail: thumbnail/dropdown.jpg
8+
language: r
9+
page_type: example_index
10+
has_thumbnail: true
11+
display_as:
12+
order: 7
13+
---
14+
15+
```{r, echo = FALSE, message=FALSE}
16+
knitr::opts_chunk$set(message = FALSE)
17+
Sys.setenv("plotly_username"="RPlotBot")
18+
Sys.setenv("plotly_api_key"="q0lz6r5efr")
19+
```
20+
# Dropdowns
21+
22+
##### Check out our <b>[reference page](https://plot.ly/r/reference/#layout-shapes)</b> for more information on using shapes!
23+
24+
### Simple Dropdown Menu Example
25+
```{r, results='hide'}
26+
library(plotly)
27+
library(MASS)
28+
29+
covmat %
30+
add_markers(marker = list(opacity = 0.3, line = list(color = "black", width = 1)))
31+
32+
p % layout(
33+
title = "Drop down menus - Plot type",
34+
xaxis = list(domain = c(0.1, 1)),
35+
yaxis = list(title = "y"),
36+
updatemenus = list(
37+
list(
38+
y = 0.8,
39+
buttons = list(
40+
41+
list(method = "restyle",
42+
args = list("type", "scatter"),
43+
label = "Scatter"),
44+
45+
list(method = "restyle",
46+
args = list("type", "histogram2d"),
47+
label = "2D Histogram")))
48+
))
49+
```
50+
```{r, results='asis', echo=FALSE, message=FALSE}
51+
plotly_POST(p, filename="dropdown/simple")
52+
```
53+
54+
### Add Two Dropdown Menus to Restyle Graph
55+
```{r, results='hide'}
56+
library(plotly)
57+
x %
58+
add_lines(y = ~y1, name = "A") %&gt;%
59+
add_lines(y = ~y2, name = "B", visible = F)
60+
61+
62+
p % layout(
63+
title = "Drop down menus - Styling",
64+
xaxis = list(domain = c(0.1, 1)),
65+
yaxis = list(title = "y"),
66+
updatemenus = list(
67+
list(
68+
y = 0.8,
69+
buttons = list(
70+
71+
list(method = "restyle",
72+
args = list("line.color", "blue"),
73+
label = "Blue"),
74+
75+
list(method = "restyle",
76+
args = list("line.color", "red"),
77+
label = "Red"))),
78+
79+
list(
80+
y = 0.7,
81+
buttons = list(
82+
list(method = "restyle",
83+
args = list("visible", list(TRUE, FALSE)),
84+
label = "Sin"),
85+
86+
list(method = "restyle",
87+
args = list("visible", list(FALSE, TRUE)),
88+
label = "Cos")))
89+
))
90+
```
91+
```{r, results='asis', echo=FALSE, message=FALSE}
92+
plotly_POST(p, filename="dropdowns/two_dropdowns")
93+
```

0 commit comments

Comments
 (0)