Below are the solutions to these exercises on Building Shiny App.
Learn more about Shiny in the online course R Shiny Interactive Web Apps – Next Level Data Visualization. In this course you will learn how to create advanced Shiny web apps; embed video, pdfs and images; add focus and zooming tools; and many other functionalities (30 lectures, 3hrs.).
#################### # # # 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/html/iris.html"), "data set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 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 set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise 3 # # # #################### # 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 set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise 4 # # # #################### # 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 set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise 5 # # # #################### # 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 set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise 6 # # # #################### # 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 set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise 7 # # # #################### # 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 set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 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 set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) )) #################### # # # Exercise 9 # # # #################### # 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 set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 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 set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ) ))
Leave a Reply