I am trying to create a chart which has dropdowns included. These will select specified values of one of the plotted variables to give 11 different plots.
I am able to use updatemenus and butons to create the dropdowns and they all select the correct observations when selected. However, because I am limited to using one input dataset, the initial view of the plot contains all the data in the input dataset - I do not want this, I would like my initial view to be of a subset of the data. Is this possible? I have tried to subset the initial data argument in at the beginning of the plot_ly statement but to no avail.
If it is not possible to give an initial view of a subset of the data, is it possible to use dropdowns and buttons to select different datasets? That way i could have 11 separate datasets and cycle between them with the dropdowns.
A sample of mu code is below:
l <- list(x = 1, y = 1, bgcolor = “#E2E2E2”, bordercolor = “#FFFFFF”, borderwidth = 2)
m <- list(b = 120)
p <- plot_ly(test_full) %>%
add_trace(
x = ~ S_NO,
y = ~ U_L_n,
type = ‘scatter’,
mode = ‘lines’,
name = ‘Control Limits’,
line = list(color = ‘rgba(190, 190, 190, .9)’, width = 1),
opacity = 0.8,
hoverinfo = ‘none’
) %>%
add_trace(
x = ~ S_NO,
y = ~ L_L_n,
type = ‘scatter’,
mode = ‘lines’,
showlegend = FALSE,
line = list(color = ‘rgba(190, 190, 190, .9)’, width = 1),
opacity = 0.8,
hoverinfo = ‘none’
) %>%
add_trace(
x = ~ S_NO,
y = ~ V_n,
type = “scatter”,
mode = “lines”,
name = “Score”,
line = list(color = ‘rgba(80, 134, 81, .9)’, width = 1),
) %>%
layout(
updatemenus = list(list(
buttons = list(
list(
method = “restyle”,
args = list(“x”, list(
subset(test_full$S_NO, test_full[, 12] == 99)
)),
label = “Show A”
),
list(
method = “restyle”,
args = list(“x”, list(
subset(test_full$S_NO, test_full[, 12] == 101)
)),
label = “Show B”
)
)
)),
xaxis = list(
title = “S number (chronological)”,
titlefont = list(size = 20),
rangeslider = list(type = “date”)
),
yaxis = list(title = “Cumulative Score”, titlefont = list(size = 20)),
legend = l,
margin = m,
hovermode = “x”
)