Hi all,
I have a dataframe which contains the columns “country”, “continent” and “value”.
I would like to program two dropdown menues which display the respective graph (column “value”):
- dropdown: User can select the continent
and in the 2. dropdown field are only the countries which have the same continent as selected in the first dropdown menue.
I am using R Studio, Rmarkdown and Plot_ly
Example:
- dropdown menue (continent): “Europe” selected
- dropdown menue: “Austria” selected
Result: shows the graph of the “value” column for Austria.
I basically have the two dropdown menues (and the entries) but I can’t connect them with each other.
Can anyone help me?
My code is:
continents <- c("Africa", "Asia", "Australia", "Europe", "North America", "South America")
p2 <- Data_local_indices_m %>%
unnest(.sep = "_") %>%
mutate(data_date=as.yearmon(data_date)) %>%
select(country,data_date,IS_data_turb) %>%
plot_ly(
mode = 'lines',
x = ~data_date,
y = ~IS_data_turb,
transforms = list(
list(
type = 'filter',
target = ~country,
operation = '==',
value = unique(Data_local_indices_m$country)[1]))) %>%
layout(
updatemenus = list(list(
active = 3,
y = 0.9,
buttons = list(
list(method = "restyle",
args = list("visible", list(FALSE, TRUE)),
label = continents[1]),
list(method = "restyle",
args = list("visible", list(FALSE, TRUE)),
label = continents[2]),
list(method = "restyle",
args = list("visible", list(FALSE, TRUE)),
label = continents[3]),
list(method = "restyle",
args = list("visible", list(TRUE, FALSE)),
label = continents[4]),
list(method = "restyle",
args = list("visible", list(FALSE, TRUE)),
label = continents[5]),
list(method = "restyle",
args = list("visible", list(FALSE, TRUE)),
label = continents[6]))),
list(
#active = 0,
y = 0.8,
x = -0.101,
buttons = list(
list(
method = "restyle",
args = list("transforms[0].value", unique(Data_local_indices_m$country)[1]),
label = unique(Data_local_indices_m$country)[1]),
list(method = "restyle",
args = list("transforms[0].value", unique(Data_local_indices_m$country)[2]),
label = unique(Data_local_indices_m$country)[2]),
list(method = "restyle",
args = list("transforms[0].value", unique(Data_local_indices_m$country)[3]),
label = unique(Data_local_indices_m$country)[3]),
list(method = "restyle",
args = list("transforms[0].value", unique(Data_local_indices_m$country)[4]),
label = unique(Data_local_indices_m$country)[4])
)
)
)
)
Many thanks for your help!