server # Define server logic required to draw a histogram - server <- function ( input, output ) ) The comment above the function explains a bit about this, but if you find it confusing, don’t worry, we’ll cover this concept in much more detail soon.
HOW TO RUN R STUDIO ON A DIFFERENT SHELL CODE
However, you’ll also notice that the code that generates the plot is wrapped in a call to renderPlot. At one level, it’s very simple – a random distribution is plotted as a histogram with the requested number of bins. The server-side of the application is shown below. The user interface is defined as follows: ui # Define UI for app that draws a histogram - ui <- fluidPage ( # App title - titlePanel ( "Hello Shiny!" ), # Sidebar layout with input and output definitions - sidebarLayout ( # Sidebar panel for inputs - sidebarPanel ( # Input: Slider for the number of bins - sliderInput ( inputId = "bins", label = "Number of bins:", min = 1, max = 50, value = 30 ) ), # Main panel for displaying outputs - mainPanel ( # Output: Histogram - plotOutput ( outputId = "distPlot" ) ) ) )
For now, though, just try playing with the sample application and reviewing the source code to get an initial feel for things. In subsequent sections of the article we’ll break down Shiny code in detail and explain the use of “reactive” expressions for generating output. The source code for both of these components is listed below.
Shiny applications have two components, a user interface object and a server function, that are passed as arguments to the shinyApp function that creates a Shiny app object from this UI/server pair. To run the example, type: library ( shiny ) runExample ( "01_hello" ) The Hello Shiny example is a simple application that plots R’s built-in faithful dataset with a configurable number of bins. This article reviews the first three examples, which demonstrate the basic structure of a Shiny app. The Shiny package comes with eleven built-in examples that demonstrate how Shiny works.