i have the following code. and i am struck. i want the first page to display just the radio buttons and based on which radio button user click, options should be displayed. for example, when user selects distributor wise, radio button, it should display drop down menu of the distributors and then display the graph based on what is selected in the drop down. i have coded the part of drop down menu, and to display graphs based on user input in the drop down, but unable to integrate the part of displaying specific menu based on radio button click from user.
my code is here
#install.packages("")
library(shiny)
library(gdata)
library(dplyr)
library(ggplot2)
library(shiny)
mydata1 = read.csv("C:\\Users\\BPO18\\Documents\\Book1.csv")
mydata<-c( "Distributor wise", "Outlet type wise", "Product name", "Product code wise", "Salesman", "State")
# subset(mydata1, row.names(mydata1) %in% mydata)
css <- "
#large .selectize-input { line-height: 40px; }
#large .selectize-dropdown { line-height: 30px; }"
ui <- fluidPage(
tags$style(type='text/css', css),
titlePanel("Hello User"),
sidebarLayout(
sidebarPanel(
radioButtons("rb", "Please select an option",
choices = c(
"Distributor wise", "Outlet type wise", "Product name", "Product code wise", "Salesman", "State")
)
),
mainPanel(
uiOutput("radiobuttonChoiceOutput")
)
)
)
shinyServer <- function(input, output, session) {
# plottype<- reactive({
# switch(input$type,
# "Distributor wise" = "s1",
# "Outlet type wise" ="s2",
# "Product name" = "s3",
# "Product code wise" = "s4",
# "Salesman" = "s5",
# "State" = "s6")
# })
#
# output$plotoptions <- renderPrint({
# print(radiobuttons("type",
# "choose : ",
# c("Distributor wise",
# "Outlet type wise",
# "Product name",
# "Product code wise",
# "Salesman",
# "State"),
# inline = TRUE
# )
# )
# })
# plotOutput(outputId="salesplot"), #placeholder
# br(), br(),
# plotOutput(outputId="salesplot1"),
# br(), br(),
# plotOutput(outputId="salesplot2"),
# br(), br(),
# plotOutput("results"),
# br(), br(),
# plotOutput("results1"),
# br(), br(),
# plotOutput("results2"))
#
# if(plottype=="s1")
# {
output$radiobuttonChoiceOutput <- renderUI({
tagList(
checkboxGroupInput("distributorInput",
h3("Distributor-wise"),
choices = unique(mydata1$distributor_name),
selected = mydata1$distributor_name[1]),
# }
# if(plottype=="s2")
# {
checkboxGroupInput("outlettpyeInput",
h3("Outlet type wise"),
choices = unique(mydata1$outlet_type),
selected = mydata1$outlet_type[1]),
# }
#
# if(plottype=="s3")
# {
checkboxGroupInput("typeInput",
h3("Product type"),
choices = unique(mydata1$prod_name),
selected = mydata1$prod_name[1]),
# }
#
# if(plottype=="s4")
# {
checkboxGroupInput("prodcodeInput",h3("Product code wise"),
choices = unique(mydata1$prod_code),
selected = mydata1$prod_code[1]),
# }
#
# if(plottype=="s5")
# {
div (id="large",
selectInput("salesmanInput", label="select the salesmen",
choices=unique(mydata1$salesman),
selected = mydata1$salesman[1])),
# }
#
# if(plottype=="s6")
# {
checkboxGroupInput("stateInput",
h3("States"),
choices = unique(mydata1$state),
selected = mydata1$state[1]))
})
# }
output$results <- renderPlot({
filtered <-
mydata1 %>%
dplyr :: filter(distributor_name == input$distributorInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("red"),
col=I("green") )
})
output$results2 <- renderPlot({
filtered <-
mydata1 %>%
dplyr :: filter(outlet_type == input$outlettpyeInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("red"),
col=I("green") )
})
output$salesplot1 <- renderPlot({
filtered <-
mydata1 %>%
filter(
prod_name == input$typeInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("blue"),
col=I("yellow") )
})
output$results1 <- renderPlot({
filtered <-
mydata1 %>%
filter(prod_code == input$prodcodeInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("red"),
col=I("green") )
})
output$salesplot <- renderPlot({
filtered <-
mydata1 %>%
filter(salesman == input$salesmanInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("darkolivegreen1"),
col=I("violet") )
})
output$salesplot2 <- renderPlot({
filtered <-
mydata1 %>%
filter(
state == input$stateInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("orange"),
col=I("blue") )
})
}
# mainPanel(
#
# }
shinyApp(ui = ui, server = shinyServer)