i ended up doing the following, but the size of the checkbox is clumsy and i would want the graphs to be displayed alongside, rather than below the checkbox. how do i go about with it?
library(shiny)
library(gdata)
library(plyr)
library(ggplot2)
library(shiny)
mydata1 = read.csv("C:\\Users\\BPO18\\Documents\\Book1.csv")
if (interactive()) {
ui <- fluidPage(
titlePanel ("Hello"),
fluidRow(
column(4, wellPanel(
radioButtons("rb", "Please select an option",
choices = c("Distributor_wise", "Outlet_type_wise"))),
wellPanel(
uiOutput("radiobuttonChoiceOutput"),
plotOutput("distributorOutput"),
plotOutput("outlettypeOutput")
))
),
column(3,
# tags$p("Distributor_wise:"),
verbatimTextOutput("distributorInput"),
# tags$p("Outlet_type_wise:"),
verbatimTextOutput("outlettyepInput")
)
)
}
shinyServer <- function(input, output, session) {
output$radiobuttonChoiceOutput <- renderUI({
switch(input$rb,
Distributor_wise = checkboxGroupInput("distributorInput",
h3("Distributor-wise"),
choices = unique(mydata1$distributor_name),
selected = mydata1$distributor_name[1]),
Outlet_type_wise = checkboxGroupInput("outlettypeInput",
h3("Outlet type wise"),
choices = unique(mydata1$outlet_type),
selected = mydata1$outlet_type[1])
)})
output$distributorOutput <- renderPlot({
filtered <-
mydata1 %>%
dplyr :: filter(distributor_name == input$distributorInput)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("red"),
col=I("green"))
})
output$outlettypeOutput <- renderPlot({
filtered <-
mydata1 %>%
dplyr :: filter(outlet_type == input$outlettypeInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("blue"),
col=I("yellow"))
})
}
shinyApp(ui=ui, server= shinyServer)