R Python
R Python
1. Modify the app.R code to use a sliderInput() function for “Cluster count”.
library(shiny)
library(ggplot2)
library(DT)
ui <- fluidPage(
titlePanel("Enhanced Shiny App"),
sidebarLayout(
sidebarPanel(
sliderInput("num", "Choose a number", value = 25, min = 1, max = 100),
sliderInput("clusters", "Cluster count:", min = 1, max = 9, value = 3),
sliderInput("sd", "Standard Deviation:", min = 0.1, max = 3, value = 1),
checkboxGroupInput("xvars", "Choose X Variable:", choices = names(iris))
),
mainPanel(
plotOutput("hist"),
DTOutput("table")
)
)
)
2. Modify the app.R code to use a checkboxGroupInput() function for the X Variable
library(shiny)
library(ggplot2)
library(DT)
ui <- fluidPage(
titlePanel("Enhanced Shiny App"),
sidebarLayout(
sidebarPanel(
sliderInput("num", "Choose a number", value = 25, min = 1, max = 100),
sliderInput("clusters", "Cluster count:", min = 1, max = 9, value = 3),
sliderInput("sd", "Standard Deviation:", min = 0.1, max = 3, value = 1),
checkboxGroupInput("xvars", "Choose X Variable:", choices = names(iris), selected =
names(iris)[1])
),
mainPanel(
plotOutput("hist"),
DTOutput("table")
)
)
)
Modified Code
library(shiny)
library(ggplot2)
ui <- fluidPage(
sliderInput(inputId = "num",
label = "Choose a number",
value = 25, min = 1, max = 100),
plotOutput("hist")
)
Screenshot
Added `library(ggplot2)`: This ensures the `ggplot2` package is loaded.
Changed `renderPlot` to use `ggplot2`:
Created a data frame from the generated random numbers.
Used `ggplot()` to create the histogram with `geom_histogram()`.
1. Modify the 02-hist-app.R code by adding an additional sliderInput for the standard
deviation for your normal random variables (hint: ?rnorm).
library(shiny)
library(ggplot2)
library(DT)
ui <- fluidPage(
titlePanel("Enhanced Histogram App"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "num",
label = "Choose a number",
value = 25, min = 1, max = 100),
sliderInput(inputId = "sd",
label = "Standard Deviation",
value = 1, min = 0.1, max = 3, step = 0.1)
),
mainPanel(
plotOutput("hist"),
DTOutput("table")
)
)
)