【发布时间】:2018-09-21 03:56:50
【问题描述】:
我正在尝试用 3 页(dtable、sales、forecast)制作一个闪亮的仪表板,到目前为止只有第一个 - 数据表显示。
销售选项卡显示所有按钮,但没有显示图表。预测选项卡也是如此。另外,我该如何调整它,所以所有按钮都以统一的方式在左侧,然后是图表?
我的方法正确吗?还是我应该使用条件面板?不能对这里的问题做出正面或反面。 我现在想让所有 3 个选项卡都响应它们各自的图。 任何帮助,将不胜感激。谢谢
wmp <- read.csv("ABC.csv",stringsAsFactors = FALSE)
UI 基本布局
ui <- dashboardPage(skin=c("blue"),
dashboardHeader(title = "Layout"),
dashboardSidebar(id="",
sidebarMenu(menuItem("Data Table", tabName = "Data_Table", icon = icon("table")),
menuItem("Sales Performance", tabName = "Sales_Performance",icon = icon("bar-chart-o")),
menuItem("Forecast",tabName = "Fore_Cast",icon = icon("bolt"))
)
),
#Main Body
dashboardBody(tabItems(
tabItem(tabName = "Data_Table",
box(title = "Data Table ",width=50,
column(2,
selectInput("PInput","Product:",c("All",unique(wmp$Product)))),
column(2,
selectInput("CInput","Category:",c("All",unique(wmp$Category)))),
column(4,
selectizeInput("PSCInput","Product Sub Category:",c("All",unique(wmp$sub.category))))), DT::dataTableOutput("table")),
tabItem(tabName = "Sales_Performance",
sidebarMenu(fluidRow(title= "Sales Breakdown",width = 500,
column(4,
sliderInput("monthInput","Month",min=1,max = 12,step = 1,c(25,45)),br()),
column(4,
selectizeInput("weekInput","Week",choices=unique(wmp$week),br())),
column(7,
selectizeInput("wdayInput","Week day",choices=unique(wmp$wday))),
column(4,
checkboxGroupInput("yearInput","Year",choices = unique(wmp$year))))),plotOutput("plot1")
#br(),br(),
#tableOutput("Results")
),
tabItem(tabName = "Fore_cast",width=400,
#UI buttons/options to be added later,
title="Plot2",plotOutput("plot2"))
)))
服务器反应部分
server <- function(input,output) {
#For Data table
output$table <- DT::renderDataTable(DT::datatable({
data1 <- wmp
if (input$PInput != "All") {
data <- data1[data1$Product == input$PInput,] }
if (input$CInput != "All") {
data <- data1[data1$Category == input$CInput,] }
if (input$PSCInput != "All") {
data1 <- data1[data1$sub.category == input$PSCInput,] }
data1
}))
#For interactive plot
filtered <- reactive({
if (is.null(input$yearInput)) {
return(NULL)
}
wmp %>% filter(
year == input$yearInput,
week == input$weekInput,
wday == input$wdayInput,
month >= input$monthInput[1],
month <= input$monthInput[2]
)})
output$plot1 <- renderPlot({
wmp2 <- data.frame(filtered())
avg <- mean((wmp2$Amount))
plotwmp2 <- ggplot(filtered(),aes(Date,Amount,group=filtered()$year,color=filtered()$year)) + scale_x_date() + geom_point() + geom_line() + xlab("Yearly Span") + theme_grey() + ggtitle("Weekly breakdown") + geom_hline(yintercept=avg,linetype="dashed", color = "red")
plotwmp2
})
#For Time series, sample plot.
output$plot2 <- renderPlot({
plot.ts(wmp$Amount)})}
#Final App
shinyApp(ui=ui, server=server)
【问题讨论】:
标签: r user-interface shiny dashboard shinydashboard