


The code above assumes that the app directory is in your working directory in such case, the file path is just the name of the directory. Note: The first argument of runApp is the file path from your working directory to the app’s directory.

For example, if your app is in a directory called my_app, run it with the following code: library(shiny) You can run a Shiny app by giving the name of its directory to the function runApp. Each Shiny app will need its own unique directory. At a minimum, an app has ui.R and server.R files, and you can create an app by making a new directory and saving the ui.R and server.R file inside it. To get your R session back, hit escape or click the stop sign icon (found in the upper right corner of the RStudio console panel).Įvery Shiny app has the same structure: two R scripts saved together in a directory. R is monitoring the app and executing the app’s reactions. Your R session will be busy while the Hello Shiny app is active, so you will not be able to run any R commands. Try to develop a feel for how the app works. Play with the Hello Shiny app and review it’s source code. We’ll cover this concept in much more detail soon. The comment above the function explains a bit about this, but if you find it confusing, don’t worry.

However, you’ll also notice that most of the script is wrapped in a call to renderPlot. It does some calculations and then plots a histogram with the requested number of bins. Hist(x, breaks = bins, col = 'darkgray', border = 'white')Īt one level, the Hello Shiny server script is very simple. # draw the histogram with the specified number of bins X <- faithful # Old Faithful Geyser dataīins <- seq(min(x), max(x), length.out = input$bins + 1) # 1) It is "reactive" and therefore should be automatically # wrapped in a call to renderPlot to indicate that: # Define server logic required to draw a histogram Here is the server.R file for the Hello Shiny example. The server.R script contains the instructions that your computer needs to build the app. # Show a plot of the generated distribution # Sidebar with a slider input for the number of bins # Define UI for application that draws a histogram Below is the ui.R script for the Hello Shiny example. It is defined in a source file named ui.R. The user interface (UI) script controls the layout and appearance of your app.
