input values => R code => output values
Reactive expressions keep track of what values they read and what values they change. If those values become “out of date”, they know their return value is out of date and will automatically recalculate.
Shiny applications have two components:
library(shiny)
# A simple/common user interface template
ui <- fluidPage(
# Application title
titlePanel("Title"),
sidebarPanel(
# Define some inputs here
),
mainPanel(
# outputs` (from the server) go here
)
)
input
and output
xxxInput (inputId, label, value)
where xxx
is the name of the widget
inputId
is the (unique) name you give to the widget (object name)label
is the text that appears with the widget in interfacevalue
all widgets have a value - the type of this value is specific to the widget# Server side logic
server <- function(input, output) {
# do something
}
library(shiny)
ui <- fluidPage()
server <- function(input, output) {
}
shinyServer(ui, server)
app.R
runApp
on folder nametextInput("text", label = h3("Text input"), value = "Enter text...")
h3()
is just converting html into a header of level 3:
h3("Hello")
<h3>Hello</h3>
selectInput("select", label = h3("What do you like?"),
choices = c("Pizza", "Ice cream",
"Donuts", "None of the above"),
selected=2)
actionButton()
- creates a clickable buttoncheckboxInput()
and checkboxGroupInput()
dateInput()
- calendar to select a datedateRangeInput()
- select a range of datesfileInput()
- upload a filenumericInput()
- input a numeric valueradioButtons()
- select one or more itemssliderInput()
- slide along a range of valuestextInput()
- input a stringrunApp("01_Hello", display.mode = "showcase")
?numericInput
).rgamma
).Shiny also has a set of output functions with general structure:
xxxOutput (outputId, ...)
where outputId
is a (unique) object name (and xxx
is one of the choices below)
html
, image
, plot
, table
, text
, creates what the names saysuiOutput
raw HTMLverbatimTextOutput
textOutputs have width and height, might be clickable, hoverable, …