Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jquery inside observeEvents

I am trying to use Jquery inside observeevent but not able to execute it.
The moment I click on "Release" button , the side bar should open. I have a Jquery here but not working. But when I put the same jquery inside onclick method, it works. But not in this method

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

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(collapsed = TRUE),
  dashboardBody(
    # Boxes need to be put in a row (or column)
actionButton("release", "Release"))
    )


server <- function(input, output) {

  useShinyjs()
  observeEvent(input$release,{
    tags$head(tags$script("$('body').toggleClass('sidebar-collapse');"))
  })
}

shinyApp(ui, server)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Move useShinyjs() to the dashboardBody (with a comma), and use the toggleClass function:

# in ui
dashboardBody(
    useShinyjs(),
    actionButton("release", "Release"))
)

# in server
observeEvent(input$release, {
    toggleClass(selector = "body", class = "sidebar-collapse")
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading