upsetjs / upsetjs_r

😠 htmlwidget R bindings for UpSet.js for rendering UpSet plots, Euler, and Venn Diagrams
https://upset.js.org/integrations/r
Other
36 stars 2 forks source link

Crosstalk example(s)/vignette #35

Closed karlmakepeace closed 1 year ago

karlmakepeace commented 1 year ago

It would be great if there were a vignette (or other/more documentation) showing the crosstalk functionality of this package.

User story

I made a brief Shiny example to test crosstalk with upsetjs out:

library(shiny)
library(upsetjs)
library(crosstalk)

listInput <- list(
  one = c(1, 2, 3, 5, 7, 8, 11, 12, 13),
  two = c(1, 2, 4, 5, 10),
  three = c(1, 5, 6, 7, 8, 9, 10, 12, 13)
)
shared_listInput <- crosstalk::SharedData$new(listInput) # create `crosstalk` R6 object

ui <- fluidPage(
  titlePanel("UpSet.js Shiny `crosstalk` Example"),
  upsetjsOutput("upsetjs_upset"),
  upsetjsOutput("upsetjs_euler"),
  upsetjsOutput("upsetjs_venn"),
  upsetjsOutput("upsetjs_karnaugh"),
)

server <- function(input, output, session) {

  shared.mode <- "hover" # otherwise default is "click"

  output$upsetjs_upset <- renderUpsetjs({
    upsetjs() %>%
      fromList(listInput,
               shared.mode = shared.mode,
               shared = shared_listInput
               ) %>%
      interactiveChart()
  })
  output$upsetjs_euler <- renderUpsetjs({
    upsetjsEulerDiagram() %>%
      fromList(listInput,
               shared.mode = shared.mode,
               shared = shared_listInput
               ) %>%
      interactiveChart()
  })
  output$upsetjs_venn <- renderUpsetjs({
    upsetjsVennDiagram() %>%
      fromList(listInput,
               shared.mode = shared.mode,
               shared = shared_listInput
               ) %>%
      interactiveChart()
  })
  output$upsetjs_karnaugh <- renderUpsetjs({
    upsetjsKarnaughMap() %>%
      fromList(listInput,
               shared.mode = shared.mode,
               shared = shared_listInput
               ) %>%
      interactiveChart()
  })
}

# Run the application
shinyApp(ui = ui, server = server)
image

Including this or something similar may be helpful to users of your package. Thank you!

sgratzl commented 1 year ago

thx will integrate it

sgratzl commented 1 year ago

note there is also an existing example at https://github.com/upsetjs/upsetjs_r/blob/main/shiny/crosstalk.R