R Tutorial: Case Studies: Building Web Applications with Shiny in R | Intro

preview_player
Показать описание

---
Hi, my name is Dean Attali, and I'm a shiny consultant as well as the author of multiple shiny-related packages and tutorials. I'll be your instructor for this course on shiny case studies.

This course assumes you already have some basic understanding of shiny. If you don't, I suggest completing an online Shiny tutorial such as the DataCamp introductory shiny course.

In this course, we'll start by reviewing some of the most fundamental Shiny concepts.

You'll then get experience developing a few Shiny apps for different real-life scenarios, while repeatedly getting exposed to essential Shiny features.

Along the way, you'll also learn some new useful skills and best practices for Shiny development.

My hope is that by the end of this course you'll be well-equiped and excited enough to develop Shiny apps for your own use.

Let's start by reviewing what a Shiny app looks like.

These 4 lines create an empty shiny application. You can use this template for any Shiny app you ever build. Let's break this down line by line:

The first line simply loads the shiny package.

The second line creates a webpage using the fluidPage function; this is called the UI, or User Interface, of a Shiny app. The UI is responsible for defining the appearance of your app. Anything you want to show in your app goes inside fluidPage.

The third line creates the server portion of the app. You can think of the server as the "brain" of the app - it's where the logic is implemented. For example, if you want to show a plot, then the UI is responsible for the location and size of the plot, but the server is responsible for generating the plot.

The last line combines the UI and the server into a Shiny app and runs it.

To add text to a Shiny app, all you need to do is add the text inside fluidPage as an argument. A shiny app with this UI definition will result in a webpage that shows the text "hello there".

The fluidPage function can actually accept as many arguments as you want. To add more strings, you simply add them all inside fluidPage, separated by commas.

Note that there is no difference visually between these two examples. The arguments passed to fluidPage are joined together, so both examples produce exactly the same result.

If instead of plain text you want your text to be formatted a little bit nicer, Shiny has many functions that can format text. For example, the h1 function is used to create primary headers,

h2 is for secondary headers,

strong is used to make text bold,

em is for italicized text, and there are many more. In order to format a piece of text, all you need to do is wrap one of these formatting functions around the text.

For example, this UI definition on the left will result in the text on the right showing up.

If you'd like to add some structure to your app, Shiny has a concept of "layouts". There are different layouts available, but we'll focus on the most basic and common one, called a sidebar layout.

Sidebar layouts provide you with a simple two-column structure,

where there's a small sidebar on the left,

and a larger main panel on the right.

You can use this code as reference to how to implement a sidebar layout. In short, you use the sidebarLayout function with two arguments: sidebarPanel and mainPanel. Each of these two panels can contain text or any other UI elements.

Let's start by building a basic shiny app.

#DataCamp #RTutorial #Building #Web #Applications #Shiny
Рекомендации по теме