ADD CONTROL WIDGETS
Welcome to the 3rd share of our series. In this share y'all volition acquire how to create in addition to house within your app the residue of the widgets which were mentioned in part 2.
More specifically nosotros volition analyze: 1)
As y'all already know from part 2 reactivity volition last added inward the upcoming parts of our serial thus this is something that y'all create non bring to worry about.
Follow the examples below to empathise the logic behind the widgets’ functions in addition to thus nurture the app y'all created in part 1 by practising amongst the practise laid nosotros prepared for you.
Firstly, nosotros volition add together all the kinds of the widgets inward our app, for educational reasons in addition to afterward nosotros volition create upward one's hear which of them is practical to keep.Let’s start!
Welcome to the 3rd share of our series. In this share y'all volition acquire how to create in addition to house within your app the residue of the widgets which were mentioned in part 2.
More specifically nosotros volition analyze: 1)
helptext
, 2) numericInput
, 3) radioButtons
, 4) selectInput
, 5) sliderInput
and 6) textInput
.As y'all already know from part 2 reactivity volition last added inward the upcoming parts of our serial thus this is something that y'all create non bring to worry about.
Follow the examples below to empathise the logic behind the widgets’ functions in addition to thus nurture the app y'all created in part 1 by practising amongst the practise laid nosotros prepared for you.
Firstly, nosotros volition add together all the kinds of the widgets inward our app, for educational reasons in addition to afterward nosotros volition create upward one's hear which of them is practical to keep.Let’s start!
Answers to the exercises are available here.
If y'all obtained a dissimilar (correct) respond than those listed on the solutions page, delight experience costless to post service your respond equally a comment on that page.
To commence amongst let’s create the infinite within our
sidebarPanel
in gild to seat inward at that topographic point the residue of our widgets. Exercise 1
Use the function
fluidrow
to brand certain that all the elements nosotros are going to usage volition last inward the same line. To create this put fluidrow
just nether the “Menu” inward your sidebarPanel in addition to unopen its parenthesis only earlier the submibutton
(excluding the two br
). HELP TEXT
In the instance below nosotros create a UI amongst a
# ui.R
helpText
.# ui.R
shinyUI(fluidPage(
titlePanel("Widgets"),
h3("Help Text"),
helpText("Text that is used to render some extra details to the user.")))
# server.R
shinyServer(function(input, output) {
})
Exercise 2
Place a
helpText
exactly nether the actionButton
, hollo it “Help Text” in addition to equally text add:”For help”. Hint: Use h4
. Exercise 3
Now use
column
function inward gild to create upward one's hear the column width for every row in addition to seat the 2 widgets inward the same line. To create this house the column
function twice. Firstly house it only earlier the “Actionbutton” championship amongst width = vi in addition to unopen its parenthesis just after the label
“Perform”. Do the same for the helpInput
. Both of the column
functions must last within the same fluidrow
. NUMERIC INPUT
In the instance below nosotros create a UI amongst a
# ui.R
numericInput
.# ui.R
shinyUI(fluidPage(
titlePanel("Widgets"),
numericInput("num",
label = h3("Numeric Input"),
value = 1)
))
# server.R
shinyServer(function(input, output) {
})
Exercise 4
Put a
numericInput
under helpText
,in the same row with submitButton
. Name it “numer”, hand it “Numeric Input” as label
and value
= 10. Hint: Use h4
, fluidrow
and column
. RADIO BUTTONS
In the instance below nosotros create a UI amongst a
#ui.R
radioButtons
.#ui.R
shinyUI(fluidPage(
titlePanel("Widgets"),
radioButtons("radio", label = h3("Radio buttons"),
choices = list("Choice 1" = 1, "Choice 2" = 2,
"Choice 3" = 3),selected = 1)
))
#server.R
shinyServer(function(input, output) {
})
Exercise 5
Add
radioButtons
under numericInput
, inward the same row with checkBoxInput
. Name it “radiobuttons”, seat as label
“Radio Buttons” in addition to hand it 2 choices amongst no default. Hint: Use h4
, fluidrow
, column
and choices
. Exercise 6
Now seat “2” equally the default of the choices. Hint: Use
selected
. SELECT INPUT
In the instance below nosotros create a UI amongst a
# ui.R
selectInput
.# ui.R
shinyUI(fluidPage(
titlePanel("Widgets"),
selectInput("select", label = h3("Select Box"),
choices = list("Choice 1" = 1, "Choice 2" = 2,
"Choice 3" = 3), selected = 1)
))
#server.R
shinyServer(function(input, output) {
})
Exercise 7
Place under
Place under
radiobuttons
and inward the same row with checkBoxGroupInput
a selectinput
. Its name
should last “select”, its label
“Select Box” in addition to y'all should hand it two choices
with the minute i equally default. Hint: Use h4
, fluidrow
, column
, choices
and selected
. SLIDER INPUT
In the instance below nosotros create a UI amongst two
# ui.R
sliderInput
.# ui.R
shinyUI(fluidPage(
titlePanel("Widgets"),
sliderInput("slider1", label = h3("Sliders"),
min = 0, max = 10, value = 5),
sliderInput("slider2", "",
min = 0, max = 10, value = c(3, 7))
))
#server.R
shinyServer(function(input, output) {
})
Exercise 8
Under the
selectInput
and inward the same row amongst the dateInput
place a sliderInput
with name
= slider1, label
= “Sliders”, min
= 0, max
= 100 and value
=50. Hint: Use fluidrow
, columns
and h4
. Exercise 9
Replace the
value
with a default hit “10-90” in addition to run across the difference. TEXT INPUT
In the instance below nosotros create a UI amongst a
# ui.R
textInput
.# ui.R
shinyUI(fluidPage(
titlePanel("Widgets"),
textInput("text", label = h3("Text Input"),
value = "Text..."))
)
#server.R
shinyServer(function(input, output) {
})
Exercise 10
Finally seat a
textInput
under sliderInput
and inward the same row amongst the dateRangeInput
. Name it “text”, seat as label
“Text Input” in addition to as value
“Some Text”. Hint: Use fluidrow
, column
and h4
. ___________________________________________
Below are the solutions to these exercises on Building Shiny App.
#################### # # # Exercise 1 # # # #################### # ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), br(), fluidRow( h4("Actionbutton"), actionButton("per", label = "Perform")), br(), h4("Submitbutton"), submitButton("Submit"), h4("Single Checkbox"), checkboxInput("checkbox", label = "Choice A", value = TRUE), checkboxGroupInput("checkGroup", label = h4("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 2), dateInput("date", label = h4("Date input"), value = "2016-12-01"), dateRangeInput("dates", label = h4("Date Range")), fileInput("file", label = h4("File Input"))), mainPanel(h1("Main"), img(src = "petal.jpg", height = 150, width = 200), br(), br(), p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/iris.html"), "data laid gives the measurements inward centimeters of the variables sepal length in addition to width in addition to petal length in addition to width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise 2 # # # #################### # ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), br(), fluidRow( h4("Actionbutton"), actionButton("per", label = "Perform"), h4("Help Text"), helpText("Just for help")), br(), h4("Submitbutton"), submitButton("Submit"), h4("Single Checkbox"), checkboxInput("checkbox", label = "Choice A", value = TRUE), checkboxGroupInput("checkGroup", label = h4("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 2), dateInput("date", label = h4("Date input"), value = "2016-12-01"), dateRangeInput("dates", label = h4("Date Range")), fileInput("file", label = h4("File Input"))), mainPanel(h1("Main"), img(src = "petal.jpg", height = 150, width = 200), br(), br(), p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inward centimeters of the variables sepal length in addition to width in addition to petal length in addition to width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise iii # # # #################### # ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), br(), fluidRow( column(6, h4("Actionbutton"), actionButton("per", label = "Perform")), column(6, h4("Help Text"), helpText("Just for help"))), br(), h4("Submitbutton"), submitButton("Submit"), h4("Single Checkbox"), checkboxInput("checkbox", label = "Choice A", value = TRUE), checkboxGroupInput("checkGroup", label = h4("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 2), dateInput("date", label = h4("Date input"), value = "2016-12-01"), dateRangeInput("dates", label = h4("Date Range")), fileInput("file", label = h4("File Input"))), mainPanel(h1("Main"), img(src = "petal.jpg", height = 150, width = 200), br(), br(), p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inward centimeters of the variables sepal length in addition to width in addition to petal length in addition to width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise four # # # #################### # ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), br(), fluidRow( column(6, h4("Actionbutton"), actionButton("per", label = "Perform")), column(6, h4("Help Text"), helpText("Just for help"))), br(), fluidRow( column(6, h4("Submitbutton"), submitButton("Submit")), column(6, numericInput("numer", label = h4("Numeric Input"), value = 10))), h4("Single Checkbox"), checkboxInput("checkbox", label = "Choice A", value = TRUE), checkboxGroupInput("checkGroup", label = h4("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 2), dateInput("date", label = h4("Date input"), value = "2016-12-01"), dateRangeInput("dates", label = h4("Date Range")), fileInput("file", label = h4("File Input"))), mainPanel(h1("Main"), img(src = "petal.jpg", height = 150, width = 200), br(), br(), p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inward centimeters of the variables sepal length in addition to width in addition to petal length in addition to width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise five # # # #################### # ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), br(), fluidRow( column(6, h4("Actionbutton"), actionButton("per", label = "Perform")), column(6, h4("Help Text"), helpText("Just for help"))), br(), fluidRow( column(6, h4("Submitbutton"), submitButton("Submit")), column(6, numericInput("numer", label = h4("Numeric Input"), value = 10))), fluidRow( column(6, h4("Single Checkbox"), checkboxInput("checkbox", label = "Choice A", value = TRUE)), column(6, radioButtons("radiobuttons", label = h4("Radio Buttons"), choices = list("Choice 1" = 1, "Choice 2" = 2) ))), checkboxGroupInput("checkGroup", label = h4("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 2), dateInput("date", label = h4("Date input"), value = "2016-12-01"), dateRangeInput("dates", label = h4("Date Range")), fileInput("file", label = h4("File Input"))), mainPanel(h1("Main"), img(src = "petal.jpg", height = 150, width = 200), br(), br(), p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inward centimeters of the variables sepal length in addition to width in addition to petal length in addition to width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise vi # # # #################### # ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), br(), fluidRow( column(6, h4("Actionbutton"), actionButton("per", label = "Perform")), column(6, h4("Help Text"), helpText("Just for help"))), br(), fluidRow( column(6, h4("Submitbutton"), submitButton("Submit")), column(6, numericInput("numer", label = h4("Numeric Input"), value = 10))), fluidRow( column(6, h4("Single Checkbox"), checkboxInput("checkbox", label = "Choice A", value = TRUE)), column(6, radioButtons("radio", label = h4("Radio Buttons"), choices = list("Choice 1" = 1, "Choice 2" = 2), selected = 2))), checkboxGroupInput("checkGroup", label = h4("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 2), dateInput("date", label = h4("Date input"), value = "2016-12-01"), dateRangeInput("dates", label = h4("Date Range")), fileInput("file", label = h4("File Input"))), mainPanel(h1("Main"), img(src = "petal.jpg", height = 150, width = 200), br(), br(), p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inward centimeters of the variables sepal length in addition to width in addition to petal length in addition to width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise seven # # # #################### # ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), br(), fluidRow( column(6, h4("Actionbutton"), actionButton("per", label = "Perform")), column(6, h4("Help Text"), helpText("Just for help"))), br(), fluidRow( column(6, h4("Submitbutton"), submitButton("Submit")), column(6, numericInput("numer", label = h4("Numeric Input"), value = 10))), fluidRow( column(6, h4("Single Checkbox"), checkboxInput("checkbox", label = "Choice A", value = TRUE)), column(6, radioButtons("radio", label = h4("Radio Buttons"), choices = list("Choice 1" = 1, "Choice 2" = 2), selected = 2))), fluidRow( column(6, checkboxGroupInput("checkGroup", label = h4("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 2)), column(6, selectInput("select", label = h4("Select Box"), choices = list("Choice 1" = 1, "Choice 2" = 2 ), selected = 1))), dateInput("date", label = h4("Date input"), value = "2016-12-01"), dateRangeInput("dates", label = h4("Date Range")), fileInput("file", label = h4("File Input"))), mainPanel(h1("Main"), img(src = "petal.jpg", height = 150, width = 200), br(), br(), p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inward centimeters of the variables sepal length in addition to width in addition to petal length in addition to width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise 8 # # # #################### # ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), br(), fluidRow( column(6, h4("Actionbutton"), actionButton("per", label = "Perform")), column(6, h4("Help Text"), helpText("Just for help"))), br(), fluidRow( column(6, h4("Submitbutton"), submitButton("Submit")), column(6, numericInput("numer", label = h4("Numeric Input"), value = 10))), fluidRow( column(6, h4("Single Checkbox"), checkboxInput("checkbox", label = "Choice A", value = TRUE)), column(6, radioButtons("radio", label = h4("Radio Buttons"), choices = list("Choice 1" = 1, "Choice 2" = 2), selected = 2))), fluidRow( column(6, checkboxGroupInput("checkGroup", label = h4("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 2)), column(6, selectInput("select", label = h4("Select Box"), choices = list("Choice 1" = 1, "Choice 2" = 2 ), selected = 1))), fluidRow( column(6, dateInput("date", label = h4("Date input"), value = "2016-12-01")), column(6, sliderInput("slider1", label = h4("Sliders"), min = 0, max = 100, value = 50))), dateRangeInput("dates", label = h4("Date Range")), fileInput("file", label = h4("File Input"))), mainPanel(h1("Main"), img(src = "petal.jpg", height = 150, width = 200), br(), br(), p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inward centimeters of the variables sepal length in addition to width in addition to petal length in addition to width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise ix # # # #################### # ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), br(), fluidRow( column(6, h4("Actionbutton"), actionButton("per", label = "Perform")), column(6, h4("Help Text"), helpText("Just for help"))), br(), fluidRow( column(6, h4("Submitbutton"), submitButton("Submit")), column(6, numericInput("numer", label = h4("Numeric Input"), value = 10))), fluidRow( column(6, h4("Single Checkbox"), checkboxInput("checkbox", label = "Choice A", value = TRUE)), column(6, radioButtons("radio", label = h4("Radio Buttons"), choices = list("Choice 1" = 1, "Choice 2" = 2), selected = 2))), fluidRow( column(6, checkboxGroupInput("checkGroup", label = h4("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 2)), column(6, selectInput("select", label = h4("Select Box"), choices = list("Choice 1" = 1, "Choice 2" = 2 ), selected = 1))), fluidRow( column(6, dateInput("date", label = h4("Date input"), value = "2016-12-01")), column(6, sliderInput("slider1", label = h4("Sliders"), min = 0, max = 100, value = c(10,90)))), dateRangeInput("dates", label = h4("Date Range")), fileInput("file", label = h4("File Input"))), mainPanel(h1("Main"), img(src = "petal.jpg", height = 150, width = 200), br(), br(), p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inward centimeters of the variables sepal length in addition to width in addition to petal length in addition to width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise 10 # # # #################### # ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), br(), fluidRow( column(6, h4("Actionbutton"), actionButton("per", label = "Perform")), column(6, h4("Help Text"), helpText("Just for help"))), br(), fluidRow( column(6, h4("Submitbutton"), submitButton("Submit")), column(6, numericInput("numer", label = h4("Numeric Input"), value = 10))), fluidRow( column(6, h4("Single Checkbox"), checkboxInput("checkbox", label = "Choice A", value = TRUE)), column(6, radioButtons("radio", label = h4("Radio Buttons"), choices = list("Choice 1" = 1, "Choice 2" = 2), selected = 2))), fluidRow( column(6, checkboxGroupInput("checkGroup", label = h4("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 2)), column(6, selectInput("select", label = h4("Select Box"), choices = list("Choice 1" = 1, "Choice 2" = 2 ), selected = 1))), fluidRow( column(6, dateInput("date", label = h4("Date input"), value = "2016-12-01")), column(6, sliderInput("slider1", label = h4("Sliders"), min = 0, max = 100, value = c(10,90)))), fluidRow( column(6, dateRangeInput("dates", label = h4("Date Range"))), column(6, textInput("text", label = h4("Text Input"), value = "Some Text"))), fileInput("file", label = h4("File Input"))), mainPanel(h1("Main"), img(src = "petal.jpg", height = 150, width = 200), br(), br(), p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inward centimeters of the variables sepal length in addition to width in addition to petal length in addition to width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) ))
http://www.r-exercises.com/2016/12/25/building-shiny-app-solutions-part-3/
http://www.r-exercises.com/2016/12/25/building-shiny-app-exercises-part-3/