基本上,我想要一个有单选按钮的页面。当用户选择其中一个按钮时,它应该根据用户输入的内容进入下拉菜单。我尝试了tabsetPanel,但似乎没什么用。当从下拉列表中选择输入时,我已经预编程了下拉菜单中应该存在的内容及其各自的图形。 这是我的代码。
#install.packages("")
library(shiny)
library(gdata)
library(dplyr)
library(ggplot2)
library(shiny)
mydata1 = read.csv("C:\\Users\\BPO18\\Documents\\Book1.csv")
css <- "
#large .selectize-input { line-height: 40px; }
#large .selectize-dropdown { line-height: 30px; }"
Type <- data.frame(mydata1$Distributorwise, mydata1$Outlettypewise, mydata1$Productname, mydata1$Productcodewise, mydata1$Salesman, mydata1$State)
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(
plotOutput("radiobuttonChoiceOutput")
)
)
)
shinyServer <- function(input, output) {
output$radiobuttonChoiceOutput <- reactive({
mydata1 %>%
filter(
Type == input$rb,
div (id="large",
selectInput("salesmanInput", label="select the salesmen",
choices=unique(mydata1$salesman), selected = mydata1$salesman[1])),
checkboxGroupInput("typeInput",
h3("Product type"),
choices = unique(mydata1$prod_name), selected = mydata1$prod_name[1]),
checkboxGroupInput("stateInput",
h3("States"),
choices = unique(mydata1$state),
selected = mydata1$state[1]),
checkboxGroupInput("distributorInput",
h3("Distributor-wise"),
choices = unique(mydata1$distributor_name),
selected = mydata1$distributor_name[1]),
checkboxGroupInput("prodcodeInput",
h3("Product code wise"),
choices = unique(mydata1$prod_code),
selected = mydata1$prod_code[1]),
checkboxGroupInput("outlettpyeInput",
h3("Outlet type wise"),
choices = unique(mydata1$outlet_type),
selected = mydata1$outlet_type[1]),
mainPanel(
plotOutput(outputId="salesplot"), #placeholder
br(), br(),
plotOutput(outputId="salesplot1"), #placeholder
br(), br(),
plotOutput(outputId="salesplot2"), #placeholder
br(), br(),
tableOutput("results"), #placeholder
br(), br(),
tableOutput("results1"),
br(), br(),
tableOutput("results2"))
) })
output$salesplot <- renderPlot({
filtered <-
mydata1 %>%
filter(salesman == input$salesmanInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("orange"),
col=I("blue") )
})
output$salesplot1 <- renderPlot({
filtered <-
mydata1 %>%
filter(
prod_name == input$typeInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("blue"),
col=I("yellow") )
})
output$salesplot2 <- renderPlot({
filtered <-
mydata1 %>%
filter(
state == input$stateInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("red"),
col=I("green") )
})
output$results <- renderPlot({
filtered <-
mydata1 %>%
filter(distributor_name == input$distributorInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("red"),
col=I("green") )
})
output$results1 <- renderPlot({
filtered <-
mydata1 %>%
filter(prod_code == input$prodcodeInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("red"),
col=I("green") )
})
output$results2 <- renderPlot({
filtered <-
mydata1 %>%
filter(outlet_type == input$outlettpyeInput
)
ggplot(filtered, aes(total_sales)) +
geom_histogram(fill=I("red"),
col=I("green") )
})
}
shinyApp(ui = ui, server = shinyServer)