The ui
defines the look and feel of the app - the user interface
Use it to define where output "lives"
It also defines the inputs for the server
, where functions are actually
evaluated.
In this case - we have defined a sliderInput
, which we're calling "bins"
.
It will take on values from 1 to 50, and will start at 30.
Access the specific value the user selects within the server
, through input$bins
.
The server
function takes the input from the UI and puts it in normal R code.
In this case, we're creating one output object, called distPlot
. The result is then called through the ui
on line 30
Try removing lines 39-44, and replacing it with print(input$bins)
Feels like it should work, but it doesn't. Any ideas why?
Let's say instead of a slider, we want 5 options: 1, 5, 20, 50, or 100
We can change the input from a slider (representing continuous intervals) to radio buttons, representing discrete choices.
Just change sliderInput
to radioButtons
, and put in the appropriate choices
. You can also add a selected
argument for which it defaults to.
Let's say instead of a slider, we want 5 options: 1, 5, 20, 50, or 100
We can change the input from a slider (representing continuous intervals) to radio buttons, representing discrete choices.
Just change sliderInput
to radioButtons
, and put in the appropriate choices
. You can also add a selected
argument for which it defaults to.
05:00
Let's say we wanted to build a plot that showed the distribution of highway miles per gallon that could be faceted by year
, trans
, or class
.
Let's say you also wanted to keep a slider on there to control the number of bins.
Use radioButtons
for the variables, and sliderInput
for the bins.
You'll need to create a second entry to your ui
Use the mpg
dataset (from ggplot2)
[demo]
My recommendation: Use one of the following:
DT::datatable
reactable::reactable
Let's build a table to go below our distribution(s) that shows mean
, sd
, min
, and max
of the corresponding distribution(s)
You'll need to create a new output object in the server, and tell the ui where it should be rendered
Use renderDataTable
in the server and dataTableOutput
in the ui or renderReactable
and reactableOutput
If you want to use {dplyr}
, as I would, then you have to deal with NSE. In this case it's not that big of a deal though. Just use !!sym(input$var)
, where sym
transforms a string to a symbol.
[demo]
Instead of using a tabset with tabsetPanel
, you might want to have a navbar at the top of the page, which you can create with navbarPage
.
Can be a bit more complicated - each tabset
needs to include everything, including the sidebarPanel
(if present), could include tabsets, mainPanel
, etc.
Instead of using a tabset with tabsetPanel
, you might want to have a navbar at the top of the page, which you can create with navbarPage
.
Can be a bit more complicated - each tabset
needs to include everything, including the sidebarPanel
(if present), could include tabsets, mainPanel
, etc.
Essentially each tab from the navbar
becomes an entirely new page.
Instead of using a tabset with tabsetPanel
, you might want to have a navbar at the top of the page, which you can create with navbarPage
.
Can be a bit more complicated - each tabset
needs to include everything, including the sidebarPanel
(if present), could include tabsets, mainPanel
, etc.
Essentially each tab from the navbar
becomes an entirely new page.
Make sure to move your title so it's like navbarPage("App title",
or the rest of the pages won't look right
[demo, if we have time]
Shiny is super customizable - just scratched the surface today
The new Mastering Shiny book should be your guide for going deeper
Great for building interactive plots, but you can use it for all sorts of other things too (including text and tables)
Apps get complicated quickly
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |