Skip to content

Embed the linked display from detourr in the pandemonium app#1

Open
Divendra2006 wants to merge 1 commit intouschiLaa:mainfrom
Divendra2006:hardTest
Open

Embed the linked display from detourr in the pandemonium app#1
Divendra2006 wants to merge 1 commit intouschiLaa:mainfrom
Divendra2006:hardTest

Conversation

@Divendra2006
Copy link

This PR introduces linked 2D tour visualizations in the pandemonium Shiny app using the detourr package. The changes add interactive scatterplot animations to explore projections of the dataset.

Changes Made:

  • Updated ui.R:

Integrated bscols() to display two linked displayScatter2dOutput() components for interactive visualizations.

  • Updated server.R:

Created a shared dataset SharedData$new(as.data.frame(pred)) for linking selections across visualizations.

Implemented shinyRenderDisplayScatter2d() for two different tour paths:

  • tour1 uses grand_tour(2)
  • tour2 uses little_tour(2)

Purpose of This Change:

  • Adds interactive 2D tour visualizations using detourr
  • Implements linking and brushing with crosstalk for better data exploration.

Screenshot from 2025-03-12 21-15-26
Add this feature at the navbar

@Divendra2006
Copy link
Author

Divendra2006 commented Mar 12, 2025

@uschiLaa @gevalencia ,
I complete the hard test of pandemonium , can you review this and suggest any improvement.

@uschiLaa
Copy link
Owner

Hi @Divendra2006, I have tried and it runs well for me. However, it seems there is an issue with the color assignment, which does not match the colors in other displays in the app. Maybe you can check why this does not work properly.

@Divendra2006
Copy link
Author

Divendra2006 commented Mar 16, 2025

Hi @uschiLaa,
Thank you for reviewing the code and pointing out the issue with the color assignment . I checked and find out that this happen because the colour aesthetic in detourr is mapped to rv$groups (numeric cluster IDs) instead of the actual color values stored in rv$col.
But changing into rv$col gives a error .

can you guide me to solve this problem?

@Divendra2006
Copy link
Author

Hi @uschiLaa ,
To solve color assignment problem , when i use detourr::detourr() with tour_aes(colour = ~colour) , I reciece the following error by running this code

shiny::observeEvent(rv$groups, {
    shared_data <- crosstalk::SharedData$new(cbind(as.data.frame(pred), colour = as.factor(rv$col)))

    output$tour1 <- detourr::shinyRenderDisplayScatter2d({
        detourr::detour(shared_data, detourr::tour_aes(projection = -1, colour = ~colour)) |>
            detourr::tour_path(tourr::grand_tour(2), fps = 60) |>
            detourr::show_scatter(alpha = 0.7, axes = FALSE)
    })

    output$tour2 <- detourr::shinyRenderDisplayScatter2d({
        detourr::detour(shared_data, detourr::tour_aes(projection = -1, colour = ~colour)) |>
            detourr::tour_path(tourr::little_tour(2), fps = 60) |>
            detourr::show_scatter(alpha = 0.7, axes = FALSE)
    })
})
Error in purrr::map: ℹ In index: 2.ℹ With name: colour.Caused by error in `.f()`:! Formula shorthand must be wrapped in `where()`.  # Bad  data %>% select(~colour)  # Good  data %>% select(where(~colour))

This error suggests that detourr is internally using tidyselect functions (likely select()) in a way that's not compatible with the current tidyselect behavior.

@uschiLaa
Copy link
Owner

Can you try without the "~" for the colour argument? You might also need to pass the color palette to detourr.

@Divendra2006
Copy link
Author

Thank you for your suggestions,
Unfortunately, removing the ~ and adding the palette argument did not resolve the issue. I am still recieving the "Can't select columns that don't exist."
this is updated code

shiny::observeEvent(rv$groups, {
    shared_data <- crosstalk::SharedData$new(cbind(as.data.frame(pred), colour = rv$col))

    output$tour1 <- detourr::shinyRenderDisplayScatter2d({
        detourr::detour(shared_data, detourr::tour_aes(projection = -1, colour = rv$col, palette = rv$pal)) |>
            detourr::tour_path(tourr::grand_tour(2), fps = 60) |>
            detourr::show_scatter(alpha = 0.7, axes = FALSE)
    })

    output$tour2 <- detourr::shinyRenderDisplayScatter2d({
        detourr::detour(shared_data, detourr::tour_aes(projection = -1, colour = rv$col, palette = rv$pal)) |>
            detourr::tour_path(tourr::little_tour(2), fps = 60) |>
            detourr::show_scatter(alpha = 0.7, axes = FALSE)
    })
})

this is error that i encounter

Caused by error in `.f()`:
! Can't select columns that don't exist.
✖ Columns `#D95F02`, `#D95F02`, `#D95F02`, `#D95F02`, `#D95F02`, etc. don't exist.

@uschiLaa
Copy link
Owner

What I mean is using the column from the new version of the data frame you have created, but without the ~ since I think you can directly specify the column name. With the latest version you are trying to provide a vector for the color argument.

@Divendra2006
Copy link
Author

Thank you for pointing this ,
But the same error come when i use "colour" as the column name

shiny::observeEvent(rv$groups, {
    shared_data <- crosstalk::SharedData$new(cbind(as.data.frame(pred), colour = rv$col))

    output$tour1 <- detourr::shinyRenderDisplayScatter2d({
        detourr::detour(shared_data, detourr::tour_aes(projection = -1, colour = "colour", palette = rv$pal)) |>
            detourr::tour_path(tourr::grand_tour(2), fps = 60) |>
            detourr::show_scatter(alpha = 0.7, axes = FALSE)
    })

    output$tour2 <- detourr::shinyRenderDisplayScatter2d({
        detourr::detour(shared_data, detourr::tour_aes(projection = -1, colour = "colour", palette = rv$pal)) |>
            detourr::tour_path(tourr::little_tour(2), fps = 60) |>
            detourr::show_scatter(alpha = 0.7, axes = FALSE)
    })
})

the error comes

 Can't select columns that don't exist.
✖ Columns `#1B9E77`, `#D95F02`, and `#7570B3` don't exist.

I think the problem is in the detourr package (package's color maping logic) that misinterprets the "colour" column in data frame . It's is designed to use the column name as a reference ,but it's incorrectly using the colour values themselves as coloumn name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants