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

Crosstalk javascript breaks once combined with selectInput #124

Open
tbrittoborges opened this issue Apr 7, 2022 · 0 comments
Open

Crosstalk javascript breaks once combined with selectInput #124

tbrittoborges opened this issue Apr 7, 2022 · 0 comments

Comments

@tbrittoborges
Copy link

## pre-process the data
x <- split(iris, iris$Species)

library(shiny)

library(plotly, warn.conflicts = FALSE)
# this behavior is independent of the table implementation
# I observe the same issue with DT 
library(reactable, warn.conflicts = FALSE)

ui <- fluidPage(
  selectInput("species", "Species", names(x), selected = names(x)[[1]]),
  plotlyOutput("p1"),
  reactableOutput("d1"),
  verbatimTextOutput('t1')
)

server <- function(input, output, session) {
  rvalues <- reactiveValues()
  
  rvalues$key <- reactive({
    x[[input$species]]
  })
  
  prev_selected <- reactive(getReactableState("d1", "selected"))
  
  output$p1 <- renderPlotly({
    s <- prev_selected()
  
    if(!is.null(s)){
      col <- rep('rgba(0,0,0,.10)', nrow(rvalues$key()))
      col[s] <- 'rgba(255,0,0,1)'
    } else {
      col <- 'rgb(0,0,0)'
    }
    
    p <- rvalues$key() %>%
      plot_ly(., showlegend = FALSE) %>%
      add_markers(
        x = ~Sepal.Length,
        y = ~Sepal.Width,
        type = "scatter",
        hoverinfo = "text",
        text = ~ paste0(
          "<b>", Species, "</b>",
          "<br><i>Sepal.Length</i>= ", Sepal.Length,
          "<br><i>Sepal.Width</i> = ", Sepal.Width,
          "<br><i>Petal.Length</i> = ",  Petal.Length)
      ) 
    
    p
  })
  
  output$d1 <- renderReactable({
    rvalues$key() %>%
      reactable(
        .,
        selection = "single",
        onClick = "select"
      ) 
  })
  
  output$t1 <- renderPrint({
    s <- prev_selected()
    if(!is.null(s)){
      cat('These rows were selected:\n\n')
      cat(s, sep = ', ')
    }
  })
}

shinyApp(ui, server)

The issue occurs once changing species input. It leads to a breakdown on crosstalk javascript that is hard to track. It seems crosstalk JS is not cleaned upon option selection, which results in the problem.

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

No branches or pull requests

1 participant