highlight() fails in lineplots after crosstalk filter if plot_ly()'s "color" argument matches highlight_key()'s key
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
I am making an interactive plotly plot with R using highlight() and crosstalk filter_select() functions. However, when the argument "color" of plotly's lines match highlight_key(), it becomes impossible to highlight any light of the filtered data in the plot.
Let's say you pick up the example in "Interactive web-based data visualization with R, plotly, and shiny" by Carson Sievert, in the Figure 16.10 of the chapter 16.1 "Graphical queries"
The example provided by the book works fine, you can highlight an item after filtering data:
library(gapminder)
g <- highlight_key(gapminder, ~country)
continent_filter <- filter_select("filter", "Select a country", g, ~continent)
p <- plot_ly(g) %>%
group_by(country) %>%
add_lines(x = ~year, y = ~lifeExp, color = ~continent) %>%
layout(xaxis = list(title = "")) %>%
highlight(selected = attrs_selected(showlegend = FALSE))
bscols(continent_filter, p, widths = 12)
However, when "color" argument of add_lines() matches highlight_key() variable (in this case, ~country) it is not possible to filter AND highlight the filtered data
library(gapminder)
g <- highlight_key(gapminder, ~country)
continent_filter <- filter_select("filter", "Select a country", g, ~continent)
p <- plot_ly(g) %>%
group_by(country) %>%
# Please mind that in the next line IS NOT "color = ~continent" as in the last example
add_lines(x = ~year, y = ~lifeExp, color = ~country) %>%
layout(xaxis = list(title = "")) %>%
highlight(selected = attrs_selected(showlegend = FALSE))
bscols(continent_filter, p, widths = 12)
Is it possible to highlight items in an interactive plot_ly lineplot (because I've checked in boxplot and it works) when the color argument of plotly's plot matches the highlight_key?
I've also tried with geom_line() + ggplotly() but won't work neither
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal R reproduction using plot_ly(), add_lines(), highlight_key(), and filter_select(), comparing color = ~country with color = ~continent. Trace how line plots handle crosstalk filtering and highlighting, then verify that filtered items can still be highlighted when color matches the highlight_key() variable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100

