Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
Gammerdinger authored Sep 18, 2024
1 parent 63731a0 commit ddb845c
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions RShiny/lessons/03_visuals.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ output$<outputID> <- renderDT({

Let's use the built-in dataset `mtcars` to visualize an example of a data table within a Shiny app.

On the UI side:
* We are using the input function described earlier `checkboxGroupInput()`, which will allow users to select which columns to display from the table.
* We use the `DTOutput()` with "table" as the ID to correspond with the output object in the server side code

On the server side:
* We use `renderDT()` and provide the mtcars dataframe, using square brackets to subset the columns selected.

```
# User interface
ui <- fluidPage(
Expand All @@ -61,6 +54,13 @@ server <- function(input, output) {
shinyApp(ui = ui, server = server)
```

On the UI side:
* We are using the input function described earlier `checkboxGroupInput()`, which will allow users to select which columns to display in the table.
* We are using the `DTOutput()` funtion with "table" as the ID to correspond with the output object in the server side code

On the server side:
* We use `renderDT()` and providing the mtcars dataframe, while using square brackets to subset the columns selected.

This will visualize in the app as:

<p align="center"><iframe src="https://hcbc.connect.hms.harvard.edu/Datatable_demo/?showcase=0" width="800" height="600px" data-external="1"></iframe></p>
Expand All @@ -69,7 +69,7 @@ This will visualize in the app as:

## Creating a plot

Creating plots is an essential skill for being able to create apps in Shin, and it is exciting because there are so many ways in which you can enhance the visualization. Let's begin with first demonstrating static plots using the `mtcars` dataset again. We will be using `ggplot2`, which is part of the `tidyverse` package, so we will need to load `tidyverse`:
Creating plots is an essential skill for being able to create apps in Shiny, and it is exciting because there are so many ways in which you can enhance the visualization. Let's begin with first demonstrating static plots using the `mtcars` dataset again. We will be using `ggplot2`, which is part of the `tidyverse` package, so we will need to load `tidyverse`:

```
library(tidyverse)
Expand All @@ -91,7 +91,7 @@ output$<outputID> <- renderPlot({
})
```

In the example below we are using the `selectInput()` function to allow users to select from which column to display on the x-axis and y-axis. The choices given are the column names of the dataframe.
In the example below we are using the `selectInput()` function to allow users to select which columns to display on the x-axis and y-axis. The choices given are the column names of the dataframe.

On the server side, we place ggplot2 code inside the `renderPlot()` function, specifying what type of plot we want to draw. The `aes_string()` function allows us to provide information stored in the input object as the x and y values.

Expand Down Expand Up @@ -121,7 +121,7 @@ server <- function(input, output) {
shinyApp(ui = ui, server = server)
```

> Note: In this lesson we are using the package `ggplot2` to create our visualizations, but plots used in Shiny can also be made using the base R graphics or any other packages.
> Note: In this lesson, we are using the package `ggplot2` to create our visualizations, but plots used in Shiny can also be made using the base R graphics or any other packages.
This sample code would look like:

Expand All @@ -134,7 +134,7 @@ While the above plot was interesting for being able to select various metrics to

### Clicking

The first way that we can interact will a plot is by clicking a point on the plot. The syntax for this is a bit interesting because it has an `input` buried within an `Output` function.
The first way that we can interact with a plot is by clicking a point on the plot. The syntax for this is a bit interesting because it has an `input` buried within an `Output` function.

On the UI side:

Expand Down Expand Up @@ -189,7 +189,7 @@ This app would look like:

### Hover

Instead of clicking on points in your plot, you can instead simply hover over them and identify more information. In order to do this, we need to tweak the UI side of the app.
Instead of clicking on points in your plot, you can instead hover over them and identify more information. In order to do this, we need to tweak the UI side of the app.

On the UI side:
```
Expand Down Expand Up @@ -233,7 +233,7 @@ This app would look like:

### Brush

The last way that you can make your plots interactive is with brushing. Perhaps you notice a cluster on points in one part of your scatter plot that you'd like to investigate further. Brushing allows you to **use a rectangle to select the points that you would like to interact with**. We need a make a few changes to our UI to accommodate brushing:
The last way that you can make your plots interactive is with brushing. Perhaps you notice a cluster of points in one part of your scatter plot that you'd like to investigate further. Brushing allows you to **use a rectangle to select the points that you would like to interact with**. We need a make a few changes to our UI to accommodate brushing:

On the UI side:

Expand All @@ -254,7 +254,7 @@ On the server side we need to use:

```
output$table <- renderDT({
brushedPoints(mtcars, input$<plot_brushID>)
brushedPoints(<dataframe_used_in_plotting>, input$<plot_brushID>)
})
```

Expand Down

0 comments on commit ddb845c

Please sign in to comment.