Skip to content

multiple selectize/dynamic color brushes rendered in shiny #1584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cpsievert opened this issue Jul 22, 2019 · 5 comments · Fixed by #1936 or sthagen/plotly-plotly.R#11
Closed

multiple selectize/dynamic color brushes rendered in shiny #1584

cpsievert opened this issue Jul 22, 2019 · 5 comments · Fixed by #1936 or sthagen/plotly-plotly.R#11

Comments

@cpsievert
Copy link
Collaborator

See https://community.rstudio.com/t/r-shiny-reactive-selectize-highlight-input-in-a-plotly-plot/34480/3

@PsychlytxTD
Copy link

Hi Carson, I've come across the same issue. I'd prefer to stick with the highlight approach vs. event_data if possible. I find that the plots appear fine in my app, unless I change the value of a dateRangeInput upstream, causing the app to filter the data and reload. My code is below:

`all_cases_by_measure<- reactive({

by_measure_nested<- nested_data() %>% dplyr::mutate(data = purrr::map(data, ~ dplyr::mutate(., timepoint = 1:length(.x$date))))

by_measure<- tidyr::unnest(by_measure_nested)

by_measure<- dplyr::mutate(by_measure, timepoint = paste("Time", timepoint))

by_measure<- by_measure %>% tidyr::unite("Client", first_name, last_name, birth_date, sep = " ")

by_measure<- by_measure %>% dplyr::group_by(subscale, timepoint) %>% dplyr::mutate(mean_score = round(mean(score, na.rm = TRUE), 2)) %>% dplyr::ungroup()

by_measure$subscale<- gsub("_", "-", by_measure$subscale)

by_measure %>%
group_by(subscale) %>%
dplyr::do(
p = highlight_key(., ~Client, group = "Select A Client") %>%
plot_ly(type = 'scatter', mode = 'lines', showlegend = FALSE) %>%
add_lines(x = ~timepoint, y = ~ mean_score, text = ~paste("Mean Score:", mean_score),
line = list(width = 3, dash = 'dash'),
marker = list(symbol ="diamond-open"),
mode = 'lines+markers', hoverinfo = "text") %>%
group_by(Client) %>%
add_trace(
x = ~timepoint, y = ~score, text = ~paste("Client:", Client, "
",
"Assessment Date:", date, "
",
"Score:", score, "
",
"Change Since Previous:", sprintf("%+3.1f", change_all)
),
mode = 'lines+markers', hoverinfo = "text") %>%
layout(xaxis = list(tickangle = 45)) %>%
add_annotations(
text = ~unique(subscale),
x = 0.5, y = 1,
xref = "paper", yref = "paper",
xanchor = "center", yanchor = "bottom",
showarrow = FALSE
)
) %>%
subplot(
nrows = (NROW(.)/2) + 1,
shareY = FALSE, shareX = FALSE, titleY = FALSE
) %>% highlight(
dynamic = TRUE,
selectize = TRUE,
color = "red"
)

})

output$plot_all_cases_by_measure<- plotly::renderPlotly({

req(all_cases_by_measure())

})`

@Solomon-0xGuardian
Copy link

I am also having this issue with Plotly in R. When I "highlight" and set "selectize = TRUE" I get a second box with a vertical scroll bar. I would really like to remove this box. Any thoughts? Maybe it is because my data set is very large (scatter plot with >40,000 points). Sorry I can't share more than the image at this point as the data is proprietary. Thanks in advance!

PlotlyDoubleBox

@jbullock35
Copy link

@AFoudree, I had the same problem -- the same vertical-scroll-bar artifact when I added a selectize dropdown menu to a scatterplot. Curiously, the problem appeared only when I used type = "scattergl"; it didn't appear with type = "scatter". (I know that switching to type = "scatter" may not work for you. 40,000 points in a plot seems like a lot.)

@Solomon-0xGuardian
Copy link

@jbullock35 Thanks for the comment. I cannot believe I missed the notification on this in my inbox. I will play with the scatter type and get back to you shortly. Thanks for the advice!

@Solomon-0xGuardian
Copy link

@jbullock35 I was finally able to remove the second vertical-scroll-bar artifact! I found a solution in stack overflow (Mar 8th, 2020). It looks like the problem may be occurring because the highlight-selectize widget does not work well with shiny dashboards. The fix involves embedding java script to manually remove the scroll-bar-artifact. This solution was presented by StéphaneLaurent and can be found here: https://stackoverflow.com/questions/60583349/why-does-shiny-app-add-a-spurious-widget-to-a-plotly-graph-using-highlight-funct/62795535#62795535

Thanks again for your helpful ideas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants