crosstalk icon indicating copy to clipboard operation
crosstalk copied to clipboard

Another approach to applying default filter/select settings on render

Open jcheng5 opened this issue 3 years ago • 0 comments

Note: d3scatter needs to change as well, the renderValue method needs to end with:

        sel_handle.invokeChangeHandler();
        filter_handle.invokeChangeHandler();
library(shiny)
library(crosstalk)
library(d3scatter)

sd <- SharedData$new(iris)

ui <- fluidPage(
  filter_slider("petal_width", "Petal width", sd, column = "Petal.Width",
    selected = c(1, 2)),
  actionButton("show", "Show second scatterplot"),
  bscols(
    d3scatterOutput("scatter1"),
    uiOutput("ui")
  )
)

server <- function(input, output, session) {
  observeEvent(input$show, {
    output$ui <- renderUI({
      d3scatterOutput("scatter2")
    })
  }, once = TRUE)
  
  output$scatter1 <- renderD3scatter({
    d3scatter(sd, ~Petal.Length, ~Petal.Width)
  })
  
  output$scatter2 <- renderD3scatter({
    d3scatter(sd, ~Petal.Length, ~Petal.Width)
  })
}

shinyApp(ui, server)

jcheng5 avatar Jun 10 '21 19:06 jcheng5