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

Broken code in Chapter 14: last changed input event #145

Open
DivadNojnarg opened this issue Oct 2, 2023 · 0 comments
Open

Broken code in Chapter 14: last changed input event #145

DivadNojnarg opened this issue Oct 2, 2023 · 0 comments

Comments

@DivadNojnarg
Copy link
Owner

In this part, some internal changes to shiny cause issues now and the code raises an error:

library(shiny)

ui <- fluidPage(
  tags$script(
    HTML("
      $(document).on(
        'shiny:inputchanged',
        function(event) {
          Shiny.setInputValue(
            'last_changed',
            {
              name: event.name,
              value: event.value,
              type: event
                .binding
                .name
                .split('.')[1]
            }
          );
      });"
    )),
  textInput("test", "Test"),
  verbatimTextOutput("last_changed")
)

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

shinyApp(ui, server)
Screenshot 2023-10-02 at 23 29 21

A possible working patch:

$(document).on(
            'shiny:inputchanged',
            function(event) {
              console.log(event.name);
              if (event.name.match('(last_changed|clientdata)') === null) {
                Shiny.setInputValue(
                  '%s',
                  {
                    name: event.name,
                    value: event.value,
                    type: event.inputType,
                    binding: event.binding !== null ? event.binding.name : ''
                  }
                );
              }
          });
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