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

actionButtonStyled and updateActionButtonStyled incompatible with bslib::page_navbar #19

Open
gtducati opened this issue Mar 9, 2025 · 1 comment

Comments

@gtducati
Copy link

gtducati commented Mar 9, 2025

Having tested actionButtonStyled and updateActionButtonStyled within a bslib page_navbar through a custom Shiny module, assigning types through updateActionButtonStyled does not work. Buttons also render incorrectly:

Image

library(shiny)
library(bslib)
library(dipsaus)

templateUI <- function(id) {
  ns <- NS(id)
  ui <- bslib::page_navbar(
    theme = bs_theme(5, "sandstone", cache = FALSE),
    nav_panel(
      title = "Test",
      actionButtonStyled(ns('btn'), label = 'Click me', type = 'default'),
      actionButtonStyled(ns('btn2'), label = 'Click me2', type = 'primary')
    )
  )
}


templateServer <- function(id) {
  moduleServer(id = id, function(input, output, session) {
    ns <- session$ns
    
    btn_types = c('default',
                  'primary',
                  'info',
                  'success',
                  'warning',
                  'danger')
    
    
    observeEvent(input$btn, {
      btype = btn_types[((input$btn - 1) %% (length(btn_types) - 1)) + 1]
      updateActionButtonStyled(session, 'btn2', type = btype)
    })
    
    
    observeEvent(input$btn2, {
      updateActionButtonStyled(session, 'btn', disabled = c(FALSE, TRUE)[(input$btn2 %% 2) + 1])
    })
    
    
  })
}



#
# Testing dipsaus actionButtonStyled and updateActionButtonStyled
# within a bslib page_navbar through a custom Shiny module
#
ui <- templateUI("TEST")
server <- function(input, output, session) {
  templateServer("TEST")
}


options(shiny.host = "0.0.0.0")
options(shiny.port = 8080)

shinyApp(ui, server)
@gtducati gtducati changed the title Incompatible with BSLIB page_navbar actionButtonStyled and updateActionButtonStyled Incompatible with BSLIB page_navbar Mar 9, 2025
@gtducati gtducati changed the title actionButtonStyled and updateActionButtonStyled Incompatible with BSLIB page_navbar actionButtonStyled and updateActionButtonStyled incompatible with bslib::page_navbar Mar 9, 2025
dipterix added a commit that referenced this issue Mar 11, 2025
Fixing #19 and #20
@dipterix
Copy link
Owner

The bug was caused due to a legacy shiny issue. Old version of shiny double-resolves the html dependency, resulting in same css & js files to be loaded twice. The solution was to set the html dependency as attributes, and shiny will resolve the dependency automatically (once). This is why using shiny layout works.

However, this approach is not supported by bslib. Since shiny seems to have fixed the double-resolve issues, use_shiny_dipsaus no longer needs to set attributes (using tagList instead)

@gtducati could you try to install the dev version of dipsaus (version >= 0.3.0.9000) and check whether the issue is fixed? I'll upload to CRAN upon confirmation.

install.packages("dipsaus", repos = c("https://rave-ieeg.r-universe.dev", "https://cloud.r-project.org"))

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