timelyportfolio / sunburstR

R htmlwidget for interactive sunburst plots
http://timelyportfolio.github.io/sunburstR/articles/sunburst-2-0-0.html
Other
210 stars 123 forks source link

crosstalk support #110

Closed mark-druffel closed 3 years ago

mark-druffel commented 3 years ago

Thanks for this package, it's great. I'm wondering if it would be possible to enable crosstalk SharedData objects?

At the bottom is reproducible example of what I'm trying to do. I want to use a crosstalk ShareData object to give linked filtering between multiple htmlwidgets. The SharedData object seems to accept my json using your d3_nest function, but if I pass the SharedData object to sunburstR it says it can't unclass an environment.

I am not well versed in the object oriented frameworks so I'm not sure where to start. Either way, thanks for all the amazing libraries!

library(tidyverse)
library(sunburstR)
library(d3r)
library(crosstalk)
# Without crosstalk this works
USArrests %>% 
  rownames_to_column(var = "State") %>% 
  inner_join(tibble(State = state.name, Region = state.division)) %>%
  mutate(Country = "USA") %>% 
  select(Country, Region, State, Assault) %>% 
  d3_nest(value_cols = "Assault", root = "Country") %>% 
  sund2b(width = "100%", valueField = "Assault")

# When I create a SharedData object I get an error, `Error in unclass(x) : cannot unclass an environment`
USArrests %>% 
  rownames_to_column(var = "State") %>% 
  inner_join(tibble(State = state.name, Region = state.division)) %>%
  mutate(Country = "USA") %>% 
  select(Country, Region, State, Assault) %>% 
  d3_nest(value_cols = "Assault", root = "Country") %>% 
  SharedData$new(~key, group = ~interaction(Region, State)) %>% 
  sund2b(width = "100%", valueField = "Assault") 
cjyetman commented 3 years ago

sunburstR is not currently "Crosstalk-compatible" as defined here https://rstudio.github.io/crosstalk/authoring.html

mark-druffel commented 3 years ago

@cjyetman Thanks for the quick response, I did not see that page on crosstalk it's very helpful! I think I follow, but I'd love to confirm my understanding.

You're saying it's not crosstalk compatible because it nests data? On the article, it says it would only work if all of the row-level data is passed to the widget's JavaScript binding with all the parameters of how the aggregation was performed and the actual logic to perform said aggregation. So if I wanted to make it crosstalk compatiable, it might require a total rewrite of the d3 object in order to implement those binds and parameters?

Sorry if I'm missing the point, I'm still very remedial with htmlwidgets just trying to understand if it's even possible. Thanks so much!

cjyetman commented 3 years ago

I have next to zero knowledge about crosstalk, but what you've said sounds about right, or at least in the right direction. Looks like there's a bunch of things the developer would need to do to adapt their htmlwidget output to make it compatible. It doesn't look like something a user of this package would be able to easily add-on... it appears to require changes deeper inside the underlying code that makes the htmlwidget.

mark-druffel commented 3 years ago

Ok that's what I figured. I can go ahead and close this for now if that makes the most sense. I'll look into it myself, but I am guessing my d3 skills are not going to be good enough at this point... This library and some of the others have allowed me to avoid learning d3 outright up to this point.

Thanks again!

timelyportfolio commented 3 years ago

thanks @mark-druffel and @cjyetman yes it is possible but would require quite a bit of effort to support. We could potentially write some add-on code to quasi-support crosstalk and go from there. Currently, I have been in maintenance mode on this package, since there is relatively little interest and participation.