Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added source as an input variable for Rshiny differentiation. #295

Closed
PatrickvanZalm opened this issue Aug 16, 2023 · 2 comments
Closed
Labels

Comments

@PatrickvanZalm
Copy link

PatrickvanZalm commented Aug 16, 2023

We noticed that when there is more than 1 heatmaply in Rshiny, plotly::event_data would collect clicks for both, making differentiating between plot 1 and plot 2 very difficult.

Plotly does have an input variable called source. I make a fork of this repo and added this input variable to the Heatmaply code. Interestingly, it was easiest to overwrite the (default) source by the input source. Just pushing it to the regular heatmap object before px or py are added through the layout() function would not lead to the desired result.

https://github.com/PatrickvanZalm/heatmaply

I tested it with the following code:

devtools::load_all("/home/heatmaply")
library(shiny)
library(plotly)


ui <- fluidPage(
  titlePanel("Old Faithful Geyser Data"),
  mainPanel(
    plotlyOutput(outputId = 'heatmap')
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  
  data <- rnorm(100) %>% matrix(., 10, 10)
  hm <- heatmaply(data, source = "B")
  
  output$heatmap <- renderPlotly({
    hm
  })
  
  observe({
    click_event <- event_data("plotly_click", source = "B")
    print(click_event)
  })
}

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

If it looks good on your end, I can initiate the pull request.

@alanocallaghan
Copy link
Collaborator

Can you link me some documentation on the source feature?

@PatrickvanZalm
Copy link
Author

Hi,

Sorry, I have not done a PR before so might need a bit of guidance here.

As described in the plot_ly fuction description (https://rdrr.io/cran/plotly/src/R/plotly.R) the 'source' variable helps identify the right plot in the event_data() to retrieve events to a specific plot, as there can be more than one.

In the forked repo, all I did was overwrite the source string after the heatmap, dendogram have been added together. I tried doing it on only the heatmap, but doing so I could not capture the event correctly.

@alanocallaghan alanocallaghan changed the title Pull request: Added source as an input variable for Rshiny differentiation. Added source as an input variable for Rshiny differentiation. Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants