Reputation: 11
I successfully launched the following code that outputs two options for RadioButtons: "No" and "Yes." However, I want to add a third radio button, call it "All," that shows values of "No" and "Yes" together in one output.
How do I go about doing this?
library(shiny)
library(ggplot2)
library(dplyr)
bcl <- read.csv("testd10Apr2017V4.csv", sep = ",", stringsAsFactors = FALSE)
ui <- fluidPage(
titlePanel("Attrition VS Age"),
sidebarLayout(
sidebarPanel(
# sliderInput("priceInput", "Price", 0, 100, c(25, 40), pre = "$"),
radioButtons("typeInput", "Type",
choices = c("No", "Yes", "All"),
selected = "Yes", inline = TRUE, width = "200px"),
hr(),
helpText("Attrition no means there is no attrition")
# selectInput("countryInput", "Country",
# choices = c("CANADA", "FRANCE", "ITALY"))
),
mainPanel(
plotOutput("coolplot")
# br(), br(),
# tableOutput("results")
)
)
)
server <- function(input, output) {
output$coolplot <- renderPlot({
filtered <-
bcl %>%
filter(#Price >= input$priceInput[1],
#Price <= input$priceInput[2],
Type == input$typeInput
# Country == input$countryInput
)
g <- ggplot(filtered, aes(Age)) +
geom_histogram(color = "white", fill = "maroon")
g + ylim(0,30) + xlim(0,60)
g
})
}
shinyApp(ui = ui, server = server)
Upvotes: 1
Views: 686
Reputation: 1438
I haven't run the code since I didn't have the datafile, but something like this should work for you. Inside the server function, you can add something like below:
if (input$typeInput == "All"){
filtered <- bcl
} else {
filtered <- bcl %>%
filter(Type == input$typeInput)
}
Upvotes: 1