I currently have a code that plots stock data from a data frame, with a dropdown menu filtering the normal, outlier, and extreme data. I would also like to add a dropdown menu that separates these by product. I have 10 different products and that works fine, but I would also like to have an option to select all the product values.
This is my current code;
p <- plot_ly(data = NewData, type = ‘scatter’, x = as.character(NewData$PID), y = NewData$NewDataBreakSize, text=NewData$PID,hoverinfo=‘NewData$BacktestID’, color = NewData$BacktestID,
colors = colorRampPalette(brewer.pal(15,“Set3”))(15),mode=‘markers’, symbol=I(j), transforms = list(
list(
type=‘filter’,
target = ~isOutlier,
operation = ‘=’,
value = 0
),
list(
type=‘filter’,
target = ~Product,
operation = ‘=’,
value = ~Product
)
))%>% layout(hoverlabel=list(namelength=-1),
margin = list(l=80, b = 120, r=240),
updatemenus = list(
list(
type = ‘dropdown’,
active = 0,
buttons = list(
list(method = “restyle”,
args = list(‘transforms[0].value’, 0),
label = ‘Normal’),
list(method = “restyle”,
args = list(‘transforms[0].value’, 1),
label = ‘Outlier’),
list(method = ‘restyle’,
args = list(‘transforms[0].value’, 2),
label = ‘Extreme’))),
list(
type = ‘dropdown’,
active = 0,
buttons = list(
list(method = “restyle”,
args = list(“transforms[1].value”, unique(NewData$Product)[1]),
label = unique(NewData$Product)[1]),
list(method = “restyle”,
args = list(“transforms[1].value”, unique(NewData$Product)[2]),
label = unique(NewData$Product)[2]),
list(method = “restyle”,
args = list(“transforms[1].value”, unique(NewData$Product)[3]),
label = unique(NewData$Product)[3]),
list(method = “restyle”,
args = list(“transforms[1].value”, unique(NewData$Product)[4]),
label = unique(NewData$Product)[4]),
list(method = “restyle”,
args = list(“transforms[1].value”, unique(NewData$Product)[5]),
label = unique(NewData$Product)[5]),
list(method = “restyle”,
args = list(“transforms[1].value”, unique(NewData$Product)[6]),
label = unique(NewData$Product)[6]),
list(method = “restyle”,
args = list(“transforms[1].value”, unique(NewData$Product)[7]),
label = unique(NewData$Product)[7]),
list(method = “restyle”,
args = list(“transforms[1].value”, unique(NewData$Product)[8]),
label = unique(NewData$Product)[8]),
list(method = “restyle”,
args = list(“transforms[1].value”, unique(NewData$Product)[9]),
label = unique(NewData$Product)[9]),
list(method = “restyle”,
args = list(“transforms[1].value”, unique(NewData$Product)[10]),
label = unique(NewData$Product)[10]),
list(method = “restyle”,
args = TRUE,
label = ‘All’)
))))