library(shiny)
sales <- vroom::vroom("sales_data_sample.csv", na = "")
library(shiny)
ui <- fluidPage(
titlePanel("Sales Dashboard"),
sidebarLayout(
sidebarPanel(
selectInput("territory", "Territory", choices = unique(sales$TERRITORY)),
selectInput("customername", "Customer", choices = NULL),
selectInput("ordernumber", "Order number", choices = NULL, size = 5, selectize = FALSE),
),
mainPanel(
uiOutput("customer"),
tableOutput("data")
)
)
)
server <- function(input, output, session) {
territory <- reactive({
req(input$territory)
filter(sales, TERRITORY == input$territory)
})
customer <- reactive({
req(input$customername)
filter(territory(), CUSTOMERNAME == input$customername)
})
output$customer <- renderUI({
row <- customer()[1, ]
tags$div(
class = "well",
tags$p(tags$strong("Name: "), row$CUSTOMERNAME),
tags$p(tags$strong("Phone: "), row$PHONE),
tags$p(tags$strong("Contact: "), row$CONTACTFIRSTNAME, " ", row$CONTACTLASTNAME)
)
})
order <- reactive({
req(input$ordernumber)
customer() %>%
filter(ORDERNUMBER == input$ordernumber) %>%
arrange(ORDERLINENUMBER) %>%
select(PRODUCTLINE, QUANTITYORDERED, PRICEEACH, SALES, STATUS)
})
output$data <- renderTable(order())
observeEvent(territory(), {
updateSelectInput(session, "customername", choices = unique(territory()$CUSTOMERNAME), selected = character())
})
observeEvent(customer(), {
updateSelectInput(session, "ordernumber", choices = unique(customer()$ORDERNUMBER))
})
}
shinyApp(ui, server)
字符串
有人做过吗?谢谢!
1条答案
按热度按时间bhmjp9jg1#
以下是我的split code:
global.R
字符串
ui.R
型
server.R
型