Hi there,
I have [X, Y, Z] data for 7 different test sessions (Level variable). Each session has 24 trials (Trial_Number variable). I want to create 3D plots of the XYZ data where a dropdown menu allows the user to select the level he wants to display and a slider where he can chose which trial within the selected level he wants to display. Each trial is represented in each session.
Here are some sample data:
> DF <- data.frame(Head_Point_X = runif(10000, 0, 1),
> Head_Point_Y = runif(10000, 0, 1),
> Head_Point_Z = runif(10000, 0, 1),
> Level = sample(0:6, 10000, replace=TRUE),
> Trial_Number = sample(1:24, 10000, replace=TRUE))
I manage to create the plot, buttons and slider but the displayed data do not make sense, as moving the slider changes the dropdown value and some data do not appear at all. I’m guessing the filters in transforms are not set up correctly but I’m not sure. Any help would be greatly appreciated.
> ID = data.frame(type = c("0", "1", "2", "3", "4", "5", "6"))
>
> all_buttons <- list()
> for (i in 1:length(ID[,])) {
> all_buttons[[i]] <- list(
> method = "restyle",
> args = list("transforms[0].value", unique(ID$type[i])),
> label = ID$type[i])
> }
>
> TRIALS = data.frame(seq(1, 24, 1))
> colnames(TRIALS) <- "x"
>
> all_trials <- list()
> for (i in 1:length(TRIALS[,])) {
> all_trials[[i]] <- list(method = "restyle",
> args = list("transforms[0].value", unique(TRIALS$x[i])),
> label = TRIALS$x[i])
> }
>
> fig <-
> plot_ly(
> df,
> x = ~ Head_Point_X,
> y = ~ Head_Point_Y,
> z = ~ Head_Point_Z,
> mode = 'markers',
> size = 1,
> transforms = list(
> list(
> type = 'filter',
> target = ~ Level,
> operation = '=',
> value = df$Level
> ),
> list(
> type = 'filter',
> target = ~ Trial_Number,
> operation = '=',
> value = df$Trial_Number
> )
> )
> )
> fig <-
> fig %>% layout(
> updatemenus = list(list(
> type = 'dropdown',
> active = 0,
> buttons = all_buttons
> )),
> sliders = list(
> list(
> active = 0,
> currentvalue = list(prefix = "Trial: "),
> steps = all_trials)
> ))
>
> fig