daattali / shinyjs

💡 Easily improve the user experience of your Shiny apps in seconds
https://deanattali.com/shinyjs
Other
734 stars 119 forks source link

shinyjs::disable(selector='.foo') is evaluated using namespace inside module #187

Closed nbbn closed 5 years ago

nbbn commented 5 years ago

Hi, I've got simple problem with shinyjs, I spend day on it. code:

library(shiny)
library(shinydashboard)
library(shinyjs)

modUI <- function(id) {
  ns <- NS(id)

  tagList(
    fluidPage(
      shinyjs::useShinyjs(),
      actionButton(
        ns("btn_display_results"),
        "run bug"
      ),
      actionButton(
        ns("btn_refresh_calculation"),
        "Refresh calculation",
        class = "for_one"
      )
    ))
}

mod <- function(input, output, session) {
  observeEvent(input$btn_display_results, {
    futile.logger::flog.debug('triggered')
    shinyjs::disable(selector = '.for_one')
  })
}

ui <- fluidPage(modUI('test'))

server <- function(input, output) {
  callModule(mod,
    'test')
}

shinyApp(ui = ui, server = server)

doesn't work,

and code:

library(shiny)
library(shinydashboard)
library(shinyjs)

ui <- fluidPage(  tagList(
    fluidPage(
      shinyjs::useShinyjs(),
      actionButton(
        "btn_display_results",
        "run bug"
      ),
      actionButton(
        "btn_refresh_calculation",
        "Refresh calculation",
        class = "for_one"
      )
    )))

server <- function(input, output) {
  observeEvent(input$btn_display_results, {
    futile.logger::flog.debug('triggered')
    shinyjs::disable(selector = '.for_one')
  })
}

shinyApp(ui = ui, server = server)

works.

I know that it's a lot discussed problem. I would expect that selector should not be namespaced, or at least there should be some opt-out / warning for it.

daattali commented 5 years ago

Have you tried using the latest shinyjs version from github? I think I recently fixed a bug that sounds familiar to this.

daattali commented 5 years ago

If you look at the NEWS file, the latest version (not on CRAN) has this item:

Fix bug: shinyjs functions used inside a module with a selector argument instead of an id argument didn't work
nbbn commented 5 years ago

Indeed, it might be fixed in current trunk version. Thanks for support :)

daattali commented 4 years ago

FYI this package is finally going on CRAN this week, in case you've been waiting. I just submitted it.