Я пытаюсь добавить фильтр в график, используя r plotly. Идея состоит в том, чтобы фильтровать на основе поля isCheck
, которое имеет значения yes
и no
. Кажется, что происходит, фильтр работает и показывает столбцы только на основе фильтров. Но он показывает все значения, доступные в df. Так что, если у меня будет только 5 isCheck
= Да, это все равно покажет другие типы в моем xaxis. Вот так должна выглядеть библиотека, или я что-то упустил.
whatis <- tibble::tribble(
~type, ~isCheck, ~count,
"Apple", "No", 1,
"banana", "No", 3,
"carrots", "No", 2,
"oranges", "Yes", 2,
"watermelon", "Yes", 7,
"tomato", "Yes", 168,
"berry", "No", 17,
"raspeberry", "Yes", 24,
"kale", "No", 2,
"spinach", "No", 1,
"mango", "Yes", 1,
"peach", "Yes", 9,
"strawberry", "No", 2
)
plot_ly(
x = whatis$type,
y = whatis$count,
name = "Source",
type = "bar",
# color = I("darkgreen")
# ,
transforms = list(
list(
type = 'filter',
target = ~whatis$isCheck,
operation = '=',
value = unique(whatis$isCheck)[1]
)
)
) %>% layout(xaxis = list(title = 'Source'),
yaxis = list(title = 'Conversions'),
# barmode = 'stack',
updatemenus = list(
list(
type = 'dropdown',xanchor = 'center',
yanchor = "top",
active = 1,
buttons = list(
list(method = "restyle",
args = list("transforms[0].value", unique(whatis$isCheck)[1]),
label = unique(whatis$isCheck)[1]),
list(method = "restyle",
args = list("transforms[0].value", unique(whatis$isCheck)[2]),
label = unique(whatis$isCheck)[2])
)
)
))