Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

close a shiny app on a click

Tags:

css

onclick

shiny

At the moment the app ends when the user clicks on a button Q. I would like this app to end when the user clicks Quit on the navbar. Unfortunately I can't figure out how to do this. Will be thankful for any help!

EDIT: It would be great to know how to shift Quit tab to the right :)

ui <- shinyUI(navbarPage(title = "Test", 
        tabPanel(title = "Content",
                 actionButton(inputId = "quit", label = "Quit")
        ),
        tabPanel(title = "Quit", icon = icon("circle-o-notch"))
        )
)

server <- shinyServer(function(input,output) {
  observe({
    if (input$quit == 1) stopApp()
  })
})

shinyApp(ui, server)
like image 436
Michal Majka Avatar asked Sep 11 '15 17:09

Michal Majka


1 Answers

The solution for your problem is to create an id for the navbar, with that, you can call observer like you did but changing the input. The only problem is to identificate that you need to create a new id for the navbarPage.

shinyApp(
ui = navbarPage(title = "Test", id="navbar", 
                         tabPanel(title = "Content"),
                         tabPanel(title = "Quit", value="stop", icon = icon("circle-o-notch"))
), #Close UI

server = function(input,output,session) {
  observe({
    if (input$navbar == "stop") 
        stopApp()
  })
} #Close server 

) #Close shinyApp
like image 191
Braisly Avatar answered Oct 14 '22 06:10

Braisly