Skip to content

Bar charts with highlight only showing half the bar #2038

@davidseres

Description

@davidseres

I have an app with two plotly outputs. I want to combine them using crosstalk. When I run the app, whenever I click a bar in one of the plots, only half the bar is highlighted.

library(shiny)
library(crosstalk)
library(plotly)
require(dplyr)

df <- tibble(names = LETTERS[1:5], x = runif(5,10,20), y = runif(5,50,100))
# df <- data.frame(names = LETTERS[1:5], x = runif(5,10,20), y = runif(5,50,100))

ui <- fluidPage(
  fluidRow(
    column(4, plotlyOutput("outp1")),
    column(4, plotlyOutput("outp2"))
  )
)

server <- function(input, output, session) {
  
  hd <- highlight_key(df, ~names)
  
  output$outp1 <- renderPlotly({
    plot_ly(
      hd,
      x = ~names,
      y = ~x,
      type = "bar"
    ) %>% highlight(on = "plotly_click", off = "plotly_doubleclick")
  })
  
  output$outp2 <- renderPlotly({
    plot_ly(
      hd,
      x = ~names,
      y = ~y,
      type = "bar"
    ) %>% highlight(on = "plotly_click", off = "plotly_doubleclick")
  })
  
}

shinyApp(ui, server)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions