Harlan Nelson
Harlan Nelson

Reputation: 1502

stop running a shiny app keyboard shortcut

I am running an application from R Studio. What is the keyboard shortcut in Linux to stop running a shiny application. For example, the shortcut to start the application is CTRL + Shift + K. I looked but did not find the short-cut to stop the application. There is a red stop sign icon to stop it using the mouse.

There must be a keyboard shortcut somewhere.

Here is my YAML

---
title: "HR Analytics"
runtime: shiny
output: html_notebook
---

Upvotes: 5

Views: 1559

Answers (2)

Thomas
Thomas

Reputation: 214

Late to the party, but here goes.

If you want to stop the running Shiny application from the RStudio IDE without having to remove your hand from the keyboard, you can simply hit the Esc key. No need to include observeEvent or the like.

Note: I haven't tested this on Linux. It works for me on Windows 10 with RStudio Version 1.1.456.

Upvotes: 2

Florian
Florian

Reputation: 25385

You could also create an event for it yourself. This stops the app when the user presses ESC (27).

library(shiny)
runApp( list(ui = bootstrapPage(
  verbatimTextOutput("results"),
  tags$script('
              $(document).on("keyup", function (e) {
              Shiny.onInputChange("keypressed", e.which);
              });
              '),
  p('This is a demo app')
  )
  , server = function(input, output, session) {

observeEvent(input$keypressed,
             {
               if(input$keypressed==27)
                 stopApp()
             })
  }
))

Hope this helps!

Upvotes: 2

Related Questions