Skip to content

Heatmap z event data should derive from _z calc attribute #1393

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

Merged
merged 3 commits into from
Nov 9, 2018
Merged

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Nov 2, 2018

Closes #1141

TESTING NOTES

Run the following and make sure that by clicking on each cell of the heatmap, it prints the correct information (gee, it sure would be nice to have rstudio/shinytest#193 to unit test this!)

# devtools::install_github("ropensci/plotly#1393")
library(shiny)
library(plotly)

ui <- fluidPage(
        
        fluidRow(column(6, h4("Heatmap based on data.frame()"),
                        plotlyOutput("plot1"),
                        h4("Selected point in heatmap"),
                        verbatimTextOutput("selected1")
                ), 
                column(6, 
                        h4("Heatmap based on matrix()"),
                        plotlyOutput("plot2"),
                        h4("Selected point in heatmap"),
                        verbatimTextOutput("selected2")
                )
        )
)

server <- function(input, output) {
    
    randomValues <- rnorm(9)
    
    # Heatmap based on data.frame(): not working correctly, try to select x = b; y = 1
    output$plot1 <- renderPlotly({
                
                set.seed(1)
                myData <- data.frame(x = rep(letters[1:3], times = 3), 
                        y = rep(as.character(1:3), each = 3), value = randomValues)
                myData$value[1] <- NA
                
                plot_ly(
                        x = ~x, y = ~y, z = ~value, data = myData,
                        type = "heatmap", source = "plot1"
                )
                
            })
    
    
    output$selected1 <- renderPrint(
            event_data("plotly_click", source = "plot1")
    )
    
    
    # Heatmap based on matrix()
    output$plot2 <- renderPlotly({
                
                m <- matrix(randomValues, nrow = 3, ncol = 3, byrow = TRUE)
                m[1,1] <- NA
                
                plot_ly(
                        x = c("a", "b", "c"), y = as.character(1:3),
                        z = m, type = "heatmap", source = "plot2"
                )
                
                
            })
    
    
    output$selected2 <- renderPrint(
            event_data("plotly_click", source = "plot2")
    )
}

shinyApp(ui = ui, server = server)

@cpsievert cpsievert requested a review from schloerke November 5, 2018 22:55
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