I have a table in a shiny app that is filtered depending on the input$brush on a graph made in ggplot. So the user brushes over on some points in the chart and gets the corresponding table below. All this is working:
output$plot_brushed_points <- render_gt({
dat<-dft()%>%
select(c(4,8:16,18:19,21:38))
dat<-dat %>%
mutate(across(where(is.numeric) & !(c("ODDS1","ODDS2","ODDS3")), ~ round(.x, 3)))
res<- brushedPoints(dat,input$brush)
gt(res) %>%
opt_interactive() %>%
tab_header(md("**In-depth parameter details**")) %>%
tab_options(table.width = pct(100),
container.width = pct(150))
})
I'm switching all my graphs to echarts and thus I need to keep the same feature. I would like to get a table from the points filtered on the graph with. I'm assuming I need to get some coordinates from e_datazoom() but couldn't figure how to make it work.
Here is the code of my graph:
output$plotui1<- renderEcharts4r({
g1<- dft() %>%
select(x=xvar(),y=yvar(),sz=sz(),FSCORE, HOME,AWAY) %>%
group_by(FSCORE) %>%
mutate(game=paste(HOME,AWAY,sep="-")) %>%
e_charts(x) %>%
e_scatter(y,sz,bind = game,symbol_size = 2) %>%
e_tooltip(formatter=htmlwidgets::JS("
function(params){
var vals = params.name.split('-')
return('<strong>' + vals[0] + '-'+ vals[1] +
'</strong><br />xvar(): ' + params.value[0] + '<br />yvar(): ' + params.value[1] +
'<br />sz():' +params.value[2])
}")) %>%
e_datazoom() %>%
e_zoom(
dataZoomIndex = 1
) %>%
e_legend(bottom = 0)
g1
})
Here is a way.
It is possible with JavaScript to get the percentage of the zoom start position and the percentage of the zoom end position. They are given by the
datazoomevent. It is also possible to get the range of the x-axis. So one can get the min x-value and the max x-value of the zoomed region. And send them to Shiny withShiny.setInputValue.But when you drag a zoom handle, the
datazoomevent is continuously triggered. This is very fast, so I usedebouncein the Shiny app to slow down the reception of the min and max values.Edit: correction
I misunderstood a point. This is easier actually, as there's no need of the zoom percentage positions. So use this JS code instead: