I want to create a bar graph with plotly that shows the age group on the x axis and the prop on the y axis. Then I want to have a dropdown mwenu that update the figure by reg. My actual data has 20 regions so it will be great to a function with a loop that create the menu automatically. Something similar to this
Mdf <- Mdf <- data.frame(age=c(15,20,25,30,35,40,45),cases=c(1200,1110,2233,1445,1323,1510,910),py=c(10101,12465,452424,14240,1544,1574,1154))
Mdf <- rbind(Mdf,Mdf)
Mdf$cases[8:14] <- Mdf$cases[1:7]+3
Mdf$prop <- (Mdf$cases / Mdf$py)*100
Mdf$reg <- c(rep(1,7),rep(2,7))
library(tidyverse)
library(plotly)
p <-
plot_ly(
y = Mdf$prop,
x = Mdf$age,
type = "bar"
)
I would appreciate your help