(1) Create a folder called test_app in your R working directory
(2) Inside this folder, create the following files
make sure these files are saved as ui.r, not ui.r.txt
(3) Add this code to ui.r
library(shiny)
# Define UI for application that plots random distributions
shinyUI(pageWithSidebar(
# Application title
headerPanel("Hello Shiny!"),
# Sidebar with a slider input for number of observations
sidebarPanel(
sliderInput("obs",
"Number of observations:",
min = 0,
max = 1000,
value = 500)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
))
(4) Add this code to server.r (from the shiny website)
library(shiny)
# Define server logic required to generate and plot a random distribution
shinyServer(function(input, output) {
# Function that generates a plot of the distribution. The function
# is wrapped in a call to reactivePlot to indicate that:
#
# 1) It is "reactive" and therefore should be automatically
# re-executed when inputs change
# 2) Its output type is a plot
#
output$distPlot <- reactivePlot(function() {
# generate an rnorm distribution and plot it
dist <- rnorm(input$obs)
hist(dist)
})
})
(5) enter runApp('~/test_app')
into the console; a shiny app should open up in your browser
(6) Add the below code to the run.r file
the folder address will probably be different for you, and must be formatted with double backslashes, not with single forward slashs. The parameter 'launch.browser=TRUE' must also be added.
require(shiny)
folder_address = 'C://Users//User 1//Documents//test_app'
runApp(folder_address, launch.browser=TRUE)
(7) Add the following code to the test.bat file
The first part will be different for you; you need to find R.exe in the bin folder of your R installation. This time, the directory path is formatted with forward-slashes.
"C:\Program Files\R\R-2.15.1\bin\R.exe" CMD BATCH "run.r"
(8) Double-Click on the test.bat file; this should open the shiny app after a second or two.
(9) Right-click on the test.bat file, click 'create shortcut', and place this shortcut wherever you want.
You should now be able to run a shiny app by simply double-clicking on a shortcut. If anyone has any refinements of this method (for example, getting the command shell that pops up to stay hidden), please post in the comments section.