OSUICode icon indicating copy to clipboard operation
OSUICode copied to clipboard

Example get-input-changed-info failing

Open fernandoroa opened this issue 1 year ago • 1 comments

When running

OSUICode::run_example(
  "shiny-events/get-input-changed-info",
  package = "OSUICode"
)

or its code in: https://unleash-shiny.rinterface.com/shiny-input-gems.html?q=get-input-changed-info%22#invoke-js-events

The browsers complaint about too much recursion, so, it does not work

R version 4.3.2 (2023-10-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 23.04

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.11.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.11.0

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

time zone: America/Sao_Paulo tzcode source: system (glibc)

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] shiny_1.7.5

fernandoroa avatar Nov 13 '23 12:11 fernandoroa

Working code, as in shinyMobile:

library(shiny)

ui <- fluidPage(
  tags$script(
    HTML("
      $(document).on(
        'shiny:inputchanged',
        function(event) {
        var type;
        if (event.binding !== null) {
            type = event.binding.name !== undefined ? event.binding.name.split(\".\")[1] : \"NA\";
            Shiny.setInputValue(\"last_changed\", {
                name: event.name,
                value: event.value,
                type: type
            });
        }
      });"
    )),
  textInput("test", "Test"),
  verbatimTextOutput("last_changed2")
)

server <- function(input, output) {
  output$last_changed2 <- renderPrint(input$last_changed)
}

shinyApp(ui, server)

fernandoroa avatar Nov 13 '23 13:11 fernandoroa