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

bindEvent and bindCache not working in shinylive #132

Open
Damonsoul opened this issue May 7, 2024 · 1 comment
Open

bindEvent and bindCache not working in shinylive #132

Damonsoul opened this issue May 7, 2024 · 1 comment

Comments

@Damonsoul
Copy link

The provided code includes the usage of bindEvent and bindCache functions in a shinyApp, but it seems that they are not functioning as expected in shinylive.

Code snippet:

shinyApp(
    ui = fluidPage(
      sliderInput("x", "x", 1, 10, 5),
      sliderInput("y", "y", 1, 10, 5),
      actionButton("go", "Go"),
      div("x * y: "),
      verbatimTextOutput("txt")
    ),
    server = function(input, output) {
      r <- reactive({
        message("Doing expensive computation...")
        Sys.sleep(2)
        input$x * input$y
      }) %>%
        bindCache(input$x, input$y) %>%
        bindEvent(input$go,once = TRUE)
      output$txt <- renderText(r())
    }
  )
@gadenbuie
Copy link
Contributor

I think the issue lies in how the default cache is resolved for bindCache(). If I add cache = "session" to bindCache(), then your example works as expected.

library(shiny)

ui <- fluidPage(
  sliderInput("x", "x", 1, 10, 5),
  sliderInput("y", "y", 1, 10, 5),
  actionButton("go", "Go"),
  div("x * y: "),
  verbatimTextOutput("txt")
)

server <- function(input, output) {
  r <- reactive({
    message("Doing expensive computation...")
    Sys.sleep(2)
    input$x * input$y
  }) |>
    bindCache(input$x, input$y, cache = "session") |>
    bindEvent(input$go)

  output$txt <- renderText(r())
}

shinyApp(ui, server)

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

2 participants