Comments (3)
see e.g. https://github.com/upsetjs/upsetjs_r/blob/main/shiny/selectionP/app.R
from upsetjs_r.
OK so I've been trying to solve this problem in some different ways and I think there may actually be a bug here. These are the approaches I've tried:
library(shiny)
library(upsetjs)
library(purrr)
library(dplyr)
set_list_2_combinations <- function(set_list) {
set_list <- set_list[
order(purrr::map_int(set_list, length), decreasing = TRUE)
]
set_names <- names(set_list)
purrr::map(seq_along(set_names), ~{
lst <- combn(set_names, .x) %>% as.data.frame() %>% as.list()
names(lst) <- purrr::map_chr(lst, ~paste0(.x, collapse = "&"))
lst
}) %>% unlist(recursive = FALSE)
}
set_list <- list("A" = c(1,2,3,4,5),"B" = c(1,2,3),"C" = c(2,6,7,8))
combinations <- c(list("none" = ""), set_list_2_combinations(set_list))
# Proxy ----
# Based on the Docs this seemed like the most efficient way to implement
# setting setSelection value by updating the values with the proxy
# functions but this did not work, the setSelection did not update on click
ui_proxy <- fluidPage(
shiny::sidebarLayout(
shiny::sidebarPanel(
actionButton("reset_selection", "Reset Selection")
),
shiny::mainPanel(
upsetjs::upsetjsOutput("upset_plot")
)
)
)
server_proxy <- function(input, output, session) {
output$upset_plot <- upsetjs::renderUpsetjs({
upsetjs::upsetjs() %>%
upsetjs::fromList(set_list)
})
observeEvent(input$upset_plot_click, {
req(input$upset_plot_click$name)
upsetjs::upsetjsProxy("upset_plot", session) %>%
upsetjs::setSelection(strsplit(
isolate(input$upset_plot_click$name), split = "&"
)[[1]])
})
observeEvent(input$reset_selection, {
upsetjs::upsetjsProxy("upset_plot", session) %>%
upsetjs::setSelection("")
# NB empty string not NULL, NULL does not reset the selection
})
}
shinyApp(ui_proxy, server_proxy)
# input ----
# I went back to basics to see If I could get it working with and input
# to select the highlighted set and re-rendering the plot when the selection
# changed. Abandoning the update on click/reset on click twice temporarily
ui_input <- fluidPage(
shiny::sidebarLayout(
shiny::sidebarPanel(
selectInput(
"set_2_highlight", "Set to highlight",
choices = names(combinations)
)
),
shiny::mainPanel(
upsetjs::upsetjsOutput("upset_plot")
)
)
)
server_input <- function(input, output, session) {
output$upset_plot <- upsetjs::renderUpsetjs({
upsetjs::upsetjs() %>%
upsetjs::fromList(set_list) %>%
upsetjs::setSelection(combinations[[input$set_2_highlight]])
})
}
shinyApp(ui_input, server_input)
# reactive values ----
# I next tried a compromise still re-rendering the plot in place of proxy
# but with a reactive value that would respond to clicks in place of a direct
# input - this also did not work
ui_reactive <- fluidPage(
shiny::sidebarLayout(
shiny::sidebarPanel(
actionButton("reset_selection", "Reset Selection"),
verbatimTextOutput("split_sel")
),
shiny::mainPanel(
upsetjs::upsetjsOutput("upset_plot")
)
)
)
server_reactive <- function(input, output, session) {
output$upset_plot <- upsetjs::renderUpsetjs({
upsetjs::upsetjs() %>%
upsetjs::fromList(set_list) %>%
upsetjs::setSelection(upset_selection$selected_sets)
})
upset_selection <- reactiveValues(selected_sets = "")
observeEvent(input$upset_plot_click, {
req(input$upset_plot_click$name)
upset_selection$selected_sets <- strsplit(
input$upset_plot_click$name, split = "&"
)[[1]]
})
observeEvent(input$reset_selection, {
upset_selection$selected_sets <- ""
})
# debug info
output$split_sel <- reactive({
strsplit(
input$upset_plot_click$name, split = "&"
)[[1]]
})
}
shinyApp(ui_reactive, server_reactive)
from upsetjs_r.
re same selection: this is an odd behavior of rshiny, since it triggers an event with the same data, it won't be transferred to the server since the reactive state hasn't changed. currently investigating a workaround, e.g. by adding a nonce like an event timestamp
from upsetjs_r.
Related Issues (20)
- Accept binary matrix input or create helper function for conversion HOT 11
- create venn diagram component HOT 1
- fix rhub building warning HOT 1
- The vertical bars for the unique elements of a set show the total elements of the set instead HOT 3
- big matrices? HOT 9
- Get the information of selected part HOT 3
- add missing new layout flags: setLabelAlignment
- Is it possible to change the hoverBar text colour and rectangle on an interactive chart? HOT 2
- Problem with upsetjsVennDiagram()
- Getting empty plots HOT 4
- generateIntersections improvement HOT 2
- upsetjs and rmarkdown HOT 4
- order set names HOT 2
- Ellipses in Euler diagrams HOT 2
- "Coloring Diagrams" vignette example (vignettes/colors.Rmd) unexpected plot output
- Crosstalk example(s)/vignette HOT 2
- fix CRAN submission
- expression input bug in upsetjs?r
- add title / desc to upsetjs_r
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from upsetjs_r.