Below are the solutions to these exercises on Shiny Application Layouts.
#################### # # # Exercise 1 # # # #################### #ui.R library(shiny) tagList( navbarPage( "Title")) #server.R function(input, output) {} #################### # # # Exercise 2 # # # #################### #ui.R library(shiny) tagList( navbarPage( "Title", tabPanel("Navbar 1"), tabPanel("Navbar 2"))) #server.R function(input, output) {} #################### # # # Exercise 3 # # # #################### #ui.R library(shiny) tagList( navbarPage( "Title", tabPanel("Navbar 1", sidebarPanel(), mainPanel()), tabPanel("Navbar 2"))) #server.R function(input, output) {} #################### # # # Exercise 4 # # # #################### #ui.R library(shiny) tagList( navbarPage( "Title", tabPanel("Navbar 1", sidebarPanel( ), mainPanel( tabsetPanel( tabPanel("Table"), tabPanel("Text"), tabPanel("Header") ) )), tabPanel("Navbar 2"))) #server.R function(input, output) {} #################### # # # Exercise 5 # # # #################### #ui.R library(shiny) tagList( navbarPage( "Title", tabPanel("Navbar 1", sidebarPanel( ), mainPanel( tabsetPanel( tabPanel("Table", h4("Iris"), tableOutput("table")), tabPanel("Text"), tabPanel("Header") ) )), tabPanel("Navbar 2"))) #server.R function(input, output) { output$table <- renderTable({ iris }) } #################### # # # Exercise 6 # # # #################### #ui.R library(shiny) tagList( navbarPage( "Title", tabPanel("Navbar 1", sidebarPanel( ), mainPanel( tabsetPanel( tabPanel("Table", h4("Iris"), tableOutput("table")), tabPanel("Text", h4("VText"), verbatimTextOutput("vtxt")), tabPanel("Header") ) )), tabPanel("Navbar 2"))) #server.R function(input, output) { output$table <- renderTable({ iris }) } #################### # # # Exercise 7 # # # #################### #ui.R library(shiny) tagList( navbarPage( "Title", tabPanel("Navbar 1", sidebarPanel( sliderInput("slider","Slider input:", 1, 100, 50), tags$h5("ActionButton:"), actionButton("action", "Action")), mainPanel( tabsetPanel( tabPanel("Table", h4("Iris"), tableOutput("table")), tabPanel("Text", h4("VText"), verbatimTextOutput("vtxt")), tabPanel("Header") ) )), tabPanel("Navbar 2"))) #server.R function(input, output) { output$table <- renderTable({ iris }) output$vtxt <- renderText({ paste(input$slider) }) } #################### # # # Exercise 8 # # # #################### #ui.R library(shiny) tagList( navbarPage( "Title", tabPanel("Navbar 1", sidebarPanel( sliderInput("slider","Slider input:", 1, 100, 50), tags$h5("ActionButton:"), actionButton("action", "Action")), mainPanel( tabsetPanel( tabPanel("Table", h4("Iris"), tableOutput("table")), tabPanel("Text", h4("VText"), verbatimTextOutput("vtxt")), tabPanel("Header", h1("Header 1"), h2("Header 2")) ) )), tabPanel("Navbar 2"))) #server.R function(input, output) { output$table <- renderTable({ iris }) output$vtxt <- renderText({ paste(input$slider) }) } #################### # # # Exercise 9 # # # #################### install.packages("shinythemes") library(shinythemes) #################### # # # Exercise 10 # # # #################### #ui.R library(shinythemes) library(shiny) tagList( themeSelector(), navbarPage( "Title", tabPanel("Navbar 1", sidebarPanel( sliderInput("slider","Slider input:", 1, 100, 50), tags$h5("ActionButton:"), actionButton("action", "Action")), mainPanel( tabsetPanel( tabPanel("Table", h4("Iris"), tableOutput("table")), tabPanel("Text", h4("VText"), verbatimTextOutput("vtxt")), tabPanel("Header", h1("Header 1"), h2("Header 2")) ) )), tabPanel("Navbar 2"))) #server.R function(input, output) { output$table <- renderTable({ iris }) output$vtxt <- renderText({ paste(input$slider) }) }
Leave a Reply