Below are the solutions to these exercises on Shiny Application Layouts.
#################### # # # Exercise 1 # # # #################### #ui.R fluidPage() #server.R function(input, output) {} #################### # # # Exercise 2 # # # #################### #ui.R fluidPage( verticalLayout() ) #server.R function(input, output) {} #################### # # # Exercise 3 # # # #################### #ui.R fluidPage( verticalLayout( titlePanel("Vertical Cars") ) ) #server.R function(input, output) {} #################### # # # Exercise 4 # # # #################### #ui.R fluidPage( verticalLayout( titlePanel("Vertical Iris"), plotOutput('plot1') ) ) #server.R function(input, output) { } #################### # # # Exercise 5 # # # #################### #ui.R fluidPage( verticalLayout( titlePanel("Vertical Iris"), plotOutput('plot1'), wellPanel(selectInput('x', 'X Variable', names(iris))) ) ) #server.R function(input, output) { } #################### # # # Exercise 6 # # # #################### #ui.R fluidPage( verticalLayout( titlePanel("Vertical Iris"), plotOutput('plot1'), wellPanel(selectInput('x', 'X Variable', names(iris))), wellPanel(selectInput('y', 'Y Variable', names(iris), selected=names(iris)[[2]])), wellPanel( numericInput('clusters', 'Cluster count', 3, min = 1, max = 9))) ) #server.R function(input, output) { } #################### # # # Exercise 7 # # # #################### #ui.R fluidPage( verticalLayout( titlePanel("Vertical Iris"), plotOutput('plot1'), wellPanel(selectInput('x', 'X Variable', names(iris))), wellPanel(selectInput('y', 'Y Variable', names(iris), selected=names(iris)[[2]])), wellPanel( numericInput('clusters', 'Cluster count', 3, min = 1, max = 9))) ) #server.R function(input, output) { Data <- reactive({ iris[, c(input$x, input$y)] }) } #################### # # # Exercise 8 # # # #################### #ui.R fluidPage( verticalLayout( titlePanel("Vertical Iris"), plotOutput('plot1'), wellPanel(selectInput('x', 'X Variable', names(iris))), wellPanel(selectInput('y', 'Y Variable', names(iris), selected=names(iris)[[2]])), wellPanel( numericInput('clusters', 'Cluster count', 3, min = 1, max = 9))) ) #server.R function(input, output) { Data <- reactive({ iris[, c(input$x, input$y)] }) clusters <- reactive({ kmeans(Data(), input$clusters) }) } #################### # # # Exercise 9 # # # #################### #ui.R fluidPage( verticalLayout( titlePanel("Vertical Iris"), plotOutput('plot1'), wellPanel(selectInput('x', 'X Variable', names(iris))), wellPanel(selectInput('y', 'Y Variable', names(iris), selected=names(iris)[[2]])), wellPanel( numericInput('clusters', 'Cluster count', 3, min = 1, max = 9))) ) #server.R function(input, output) { Data <- reactive({ iris[, c(input$x, input$y)] }) clusters <- reactive({ kmeans(Data(), input$clusters) }) output$plot1 <- renderPlot({ plot(Data()) }) } #################### # # # Exercise 10 # # # #################### #ui.R fluidPage( verticalLayout( titlePanel("Vertical Iris"), plotOutput('plot1'), wellPanel(selectInput('x', 'X Variable', names(iris))), wellPanel(selectInput('y', 'Y Variable', names(iris), selected=names(iris)[[2]])), wellPanel( numericInput('clusters', 'Cluster count', 3, min = 1, max = 9))) ) #server.R function(input, output) { Data <- reactive({ iris[, c(input$x, input$y)] }) clusters <- reactive({ kmeans(Data(), input$clusters) }) output$plot1 <- renderPlot({ plot(Data(), col = clusters()$cluster, pch = 20, cex = 3) points(clusters()$centers, pch = 4, cex = 4, lwd = 4) }) }
Leave a Reply