Created
April 14, 2019 16:20
-
-
Save AliciaSchep/197f6f237b3f9ad28c7ac0b7f77db2b1 to your computer and use it in GitHub Desktop.
Plotly Dropdown Example
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
p <- plot_ly(mtcars, x = ~wt) %>% | |
add_markers(y = ~mpg, name = "A") %>% | |
add_markers(y = ~hp, name = "B", visible = F) %>% | |
layout( | |
title = "Drop down menus - Update", | |
xaxis = list(domain = c(0.1, 1)), | |
yaxis = list(title = "mpg"), | |
updatemenus = list( | |
list( | |
y = 0.7, | |
buttons = list( | |
list(method = "update", | |
args = list(list(visible = list(TRUE, FALSE)), | |
list(yaxis = list(title = "mpg"))), | |
label = "mpg"), | |
list(method = "update", | |
args = list(list(visible = list(FALSE, TRUE)), | |
list(yaxis = list(title = "hp"))), | |
label = "hp"))) | |
) | |
) | |
p <- plot_ly(mtcars) %>% | |
add_markers(x = ~wt, y = ~mpg, name = "mpg") %>% | |
add_markers(x = ~wt, y = ~hp, name = "hp", visible = FALSE) %>% | |
add_markers(x = ~gear, y = ~mpg, name = "mpg", xaxis = "x2") %>% | |
add_markers(x = ~gear, y = ~hp, name = "hp", visible = FALSE, xaxis = "x2") %>% | |
layout( | |
title = "Drop down menus - Update", | |
xaxis = list(domain = c(0.1, 0.52)), | |
xaxis2 = list(domain = c(0.58,1), title = "gear"), | |
yaxis = list(title = "mpg"), | |
showlegend = FALSE, | |
updatemenus = list( | |
list( | |
y = 0.7, | |
buttons = list( | |
list(method = "update", | |
args = list(list(visible = list(TRUE, FALSE, TRUE, FALSE)), | |
list(yaxis = list(title = "mpg"))), | |
label = "mpg"), | |
list(method = "update", | |
args = list(list(visible = list(FALSE, TRUE, FALSE, TRUE)), | |
list(yaxis = list(title = "hp"))), | |
label = "hp"))) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment