so, this is my code, and "mydata1" is a csv file with 2 columns. one column is distributor_name and it has the following data
distributor_name<-data.frame("Chhutu Enterprise" , "Durga Agency", "DeyS Agency House", "S.P Traders") . Next column is outlet_type and it has outlet_type <-data.frame("Grocer","Grocer", "Puja Outlet", "Self Service")
. i am able to show drop downs for specific option chosen by user, but graphs are not being plotted.
#install.packages("magrittr")
library(magrittr)
library(shiny)
library(gdata)
library(plyr)
library(ggplot2)
library(shiny)
mydata1 = read.csv("C:\\Users\\BPO18\\Documents\\Book1.csv")
ui <- fluidPage(
titlePanel ("Hello"),
fluidRow(
column(4, wellPanel(
radioButtons("rb", "Please select an option",
choices = c("Distributor_wise", "Outlet_type_wise"))),
wellPanel(
uiOutput("radiobuttonChoiceOutput")
)
),
column(3,
plotOutput("distributoroutput"),
plotOutput("outlettypeoutput")
)
)
)
shinyServer <- function(input, output) {
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({
if(input$rb == "Distributor_wise"){
return()
}
filtered <-
mydata1 %>%
dplyr :: filter(distributor_name == input$distributorInput)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("red"),
col=I("green"))
}, height = 400, width = 800)
output$outlettypeOutput <- renderPlot({
if(input$rb == "Outlet_type_wise"){
return()
}
filtered <-
mydata1 %>%
dplyr :: filter(outlet_type == input$outlettypeInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("blue"),
col=I("yellow"))
}, height = 400, width = 800)
}
shinyApp(ui=ui, server = shinyServer)