I am trying to find out how to show and hide my outputs like graphics and tabels each time when the user change something in the widjets. For instance I have a slider input
The reason your code didn't work is because you didn't make a call to useShinyjs()
(if you read the documentation or look at any examples of using shinyjs, you'll see that you HAVE to call useShinyjs()
in the UI).
I couldn't replicate your code because it had too many errors, but just to demonstrate that it does work with outputs, here's a small example you can run. In your project, just add shinyjs::useShinyjs()
somewhere in the UI.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
actionButton("hideshow", "Hide/show plot"),
plotOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderPlot({
plot(rnorm(100))
})
observeEvent(input$hideshow, {
# every time the button is pressed, alternate between hiding and showing the plot
toggle("plot")
})
}
shinyApp(ui = ui, server = server)