Get startedGet started for free

Getting started with shiny apps

1. Getting started with shinyApps

Welcome to the course, my name is Kee Seng and I come up with trading strategies in my day job! We shall get started with shinyApps in this video.

2. Why create a dashboard?

So, why use a dashboard instead of a standard report? A report is normally static, and provides just a snapshot of some results. Unlike a report, a dashboard is dynamic. This means that information can be updated in real time, so that the most recent results are reported. A dashboard also provides users with a more immersive experience, especially if interactive elements can be added. In R, the shinydashboard package provides an intuitive way to create a dashboard. There are plenty of modules that we can easily add to a shinydashboard, as we will see later.

3. An example of a shinydashboard

Here is an example of a shinydashboard. See that we can switch between tabs and interact with the dashboard. As we can see, there are several pages in the dashboard that each can be accessed from clicking on buttons located in the side bar. Users can provide input, and elements of the dashboard will react accordingly.

4. shinyApp

A shinydashboard is actually a type of shinyApp with special dashboard modules. As such, before we build our first shinydashboard, we will need to first understand what a shinyApp is. It all comes down to two main components. The first is a user interface, or UI for short. The second is a server.

5. The restaurant analogy

Let us now explain each of these components using an analogy. A shiny app is like a restaurant. A user of the shiny app is like a patron of the restaurant. The user interface will contain outputs and inputs. The output of a shiny app is much like the various dishes that the restaurant can offer. The input of a shiny app is like the instructions that we need to transmit in order to get the desired meal - that's the order! In that sense, we can liken the user interface of a shinyApp to the table at which we are seated. We will expect certain dishes to be placed on the table based on our instructions. We will then need someone to pass down the order to the kitchen, and then deliver the food to us. That role is played by a waiter. This is exactly what the server does in a shinyApp. It tells the app what outputs to produce based on user inputs.

6. User interface (UI)

Let us see what a shinyApp looks like in R code. To get started, we will first need to import the shiny package. The user interface is defined by the fluidPage function. We will conventionally store the fluidPage object as ui, to improve code readability, and to remind ourselves that this is the user interface. In the user interface, app elements are added. For instance, the title is added by placing a titlePanel function. The app title will then be rendered. The server is a user-defined function, which we conventionally call server. Finally, the shinyApp function glues them all together and renders the app. In this example, we have an empty app with a title.

7. The rendered shinyApp

Here is the rendered shinyApp, which is obtained by running the code in the previous slide. See that there are no inputs or outputs yet.

8. Let's practice!

Let's now practice putting together a shinyApp and check our understanding of some key concepts covered in this video.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.