Below are the solutions to these exercises on Shiny Application Layouts.
#################### # # # Exercise 1 # # # #################### install.packages("shiny") library(shiny) #################### # # # Exercise 2 # # # #################### #ui.R library(shiny) shinyUI(navbarPage("Cars", tabPanel("Plot"), tabPanel("Summary"), tabPanel("Others") )) #server.R library(shiny) function(input, output, session) {} #################### # # # Exercise 3 # # # #################### #ui.R library(shiny) shinyUI(navbarPage("Cars", tabPanel("Plot", sidebarLayout( sidebarPanel( ), mainPanel( ) )), tabPanel("Summary"), tabPanel("Others") )) #server.R library(shiny) function(input, output, session) {} #################### # # # Exercise 4 # # # #################### #ui.R library(shiny) shinyUI(navbarPage("Cars", tabPanel("Plot", sidebarLayout( sidebarPanel( radioButtons("plot", "Plot", c("Scatter"="p", "Line"="l") ) ), mainPanel( ) )), tabPanel("Summary"), tabPanel("Others") )) #server.R library(shiny) function(input, output, session) {} #################### # # # Exercise 5 # # # #################### #ui.R library(shiny) shinyUI(navbarPage("Cars", tabPanel("Plot", sidebarLayout( sidebarPanel( radioButtons("plote", "Plot", c("Scatter"="p", "Line"="l") ) ), mainPanel( plotOutput("plot") ) )), tabPanel("Summary"), tabPanel("Others") )) #server.R library(shiny) function(input, output, session) { output$plot <- renderPlot({ plot(cars, type=input$plote) }) } #################### # # # Exercise 6 # # # #################### #ui.R library(shiny) shinyUI(navbarPage("Cars", tabPanel("Plot", sidebarLayout( sidebarPanel( radioButtons("plote", "Plot", c("Scatter"="p", "Line"="l") ) ), mainPanel( plotOutput("plot") ) )), tabPanel("Summary", verbatimTextOutput("summary")), tabPanel("Others") )) #server.R library(shiny) library(markdown) function(input, output, session) { output$plot <- renderPlot({ plot(cars, type=input$plote) }) output$summary <- renderPrint({ summary(cars) }) } #################### # # # Exercise 7 # # # #################### #ui.R library(shiny) shinyUI(navbarPage("Cars", tabPanel("Plot", sidebarLayout( sidebarPanel( radioButtons("plote", "Plot", c("Scatter"="p", "Line"="l") ) ), mainPanel( plotOutput("plot") ) )), tabPanel("Summary", verbatimTextOutput("summary")), navbarMenu("Others", tabPanel("Data Table"), tabPanel("Description")) )) #server.R library(shiny) function(input, output, session) { output$plot <- renderPlot({ plot(cars, type=input$plote) }) output$summary <- renderPrint({ summary(cars) }) } #################### # # # Exercise 8 # # # #################### #ui.R library(shiny) shinyUI(navbarPage("Cars", tabPanel("Plot", sidebarLayout( sidebarPanel( radioButtons("plote", "Plot", c("Scatter"="p", "Line"="l") ) ), mainPanel( plotOutput("plot") ) )), tabPanel("Summary", verbatimTextOutput("summary")), navbarMenu("Others", tabPanel("Data Table", dataTableOutput("table")), tabPanel("Description")) )) #server.R library(shiny) function(input, output, session) { output$plot <- renderPlot({ plot(cars, type=input$plote) }) output$summary <- renderPrint({ summary(cars) }) output$table <- renderDataTable({ (cars) }) } #################### # # # Exercise 9 # # # #################### #ui.R library(shiny) shinyUI(navbarPage("Cars", tabPanel("Plot", sidebarLayout( sidebarPanel( radioButtons("plote", "Plot", c("Scatter"="p", "Line"="l") ) ), mainPanel( plotOutput("plot") ) )), tabPanel("Summary", verbatimTextOutput("summary")), navbarMenu("Others", tabPanel("Data Table", dataTableOutput("table")), tabPanel("Description", "The data give the speed of cars and the distances taken to stop. Note that the data were recorded in the 1920s." )) )) #server.R library(shiny) function(input, output, session) { output$plot <- renderPlot({ plot(cars, type=input$plote) }) output$summary <- renderPrint({ summary(cars) }) output$table <- renderDataTable({ (cars) }) } #################### # # # Exercise 10 # # # #################### #ui.R shinyUI(fluidPage( titlePanel("Cars"), navlistPanel( "Plot", tabPanel("Component 1", radioButtons("plote", "Plot", c("Scatter"="p", "Line"="l") ), plotOutput("plot")), "Summary", tabPanel("Component 3", verbatimTextOutput("summary")), "Others", tabPanel("Component 4", dataTableOutput("table")), tabPanel("Component 5", "The data give the speed of cars and the distances taken to stop. Note that the data were recorded in the 1920s." ) ) )) #server.R library(shiny) function(input, output, session) { output$plot <- renderPlot({ plot(cars, type=input$plote) }) output$summary <- renderPrint({ summary(cars) }) output$table <- renderDataTable({ (cars) }) }
Leave a Reply