Skip to content

highlight_key isn't working with shiny - TypeError: pt.pointNumber is undefined #1610

Closed
@JeremyBesson

Description

@JeremyBesson

I was trying to highlight an histogram bar with plotly and shiny.
The combinaison of functions highlight_key and highlight are working in my usecase with plotly.
But when I put this code in a shiny app, the app is crashing with the javascript error:

TypeError: pt.pointNumber is undefined

This is the code I use with plotly only:

  inputCol <- "carb"
    highlight_key(mtcars, ~carb) %>%
    plot_ly(x = ~mtcars[[inputCol]],
            type = "histogram") %>%
    layout(barmode = "overlay") %>% 
    highlight(on = "plotly_hover", off="plotly_deselect") 

This is the same code inside a shiny app:

 #### Dependencies ####
    library(shiny)
    library(plotly)
    library(plyr)

    # Define UI for application that draws a histogram
    ui <- fluidPage(
      
      # Sidebar with a slider input for number of bins 
      sidebarLayout(
        sidebarPanel(
          verbatimTextOutput("text")
        ),

        # Show a plot of the generated distribution
        mainPanel(
          plotlyOutput("distPlotTest")
        )
      )
    )
    
    # Define server logic required to draw a histogram
    server <- function(input, output) {

     
      output$distPlotTest <- renderPlotly({

        inputCol <- "carb"
        highlight_key(mtcars, ~carb) %>%
          plot_ly(x = ~mtcars[[inputCol]],
                  type = "histogram") %>%
          layout(barmode = "overlay") %>% 
          highlight(on = "plotly_hover", off="plotly_deselect") 
        
        
      })
      
    }
    
    # Run the application
    shinyApp(ui = ui, server = server) # Run the application without password

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions