Search code examples
rshinyr-leaflet

How to hide form on submit button?


I have created one absolutepanel in shiny. I have created on submit button and selectInput pane.

    selectInput("Customer", "Customer",groupcustomer),
            submitButton("Submit",icon("refresh"))

Above code is in div tag. I want to collapse i.e. hide particular div or hide form on submitButton. How can I do this?


Solution

  • The following will toggle hiding of the input form when the submit button is pushed:

    library(shiny)
    library(shinyjs)
    
    ui <- basicPage(
        useShinyjs(),
        tags$div(id="hideme",
                 selectInput("Customer", "Customer", c("bill","bob","bozo"))
                 ),
        actionButton("doSubmit", "Submit", icon("refresh"),
                     style="color: #fff; background-color: #337ab7; border-color: #2e6da4")
    )
    
    server <- function(input, output) {
        observeEvent(input$doSubmit, {
            toggle("hideme")
        })
    }
    
    shinyApp(ui, server)
    

    It replaces the submitButton with an actionButton as recommended in the help page and duplicates the style of submitButton.

    The use of submitButton is generally discouraged in favor of the more versatile actionButton (see details below).