我试图制作一个闪亮的仪表板,有3页(dtable,销售,预测),到目前为止只有第一个 - 数据表显示。
销售标签显示所有按钮,但没有显示图表。预测选项卡也是如此。另外,我怎么能调整它,所以所有按钮都以统一的方式在左边,然后是图形?
我的方法是否正确?或者我应该使用条件面板?不能在这里做出什么样的错误。 我现在想让所有3个标签响应他们各自的情节。 任何帮助,将不胜感激。谢谢
wmp <- read.csv("ABC.csv",stringsAsFactors = FALSE)
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)
答案 0 :(得分:1)
如果您想在左侧有按钮并在右侧绘图,我认为您应该将页面分成两部分。像这样:
tabItem(tabName = "Sales_Performance",
fluidRow(title= "Sales Breakdown",width = 500,
column(4,
sliderInput("monthInput","Month",min=1,max = 12,step = 1,c(25,45)),
br(),
selectizeInput("weekInput","Week",choices=unique(wmp$week)),
br(),
selectizeInput("wdayInput","Week day",choices=unique(wmp$wday)),
br(),
checkboxGroupInput("yearInput","Year",choices = unique(wmp$year))
),
column(8,
plotOutput("plot1")
)
)
)
你也可以把它放在boxes。
如果您要提供数据样本,那么绘图问题将更容易理解和修复。至于我可以判断plot2的问题不应该。 plot1代码部分&#34; plotwmp2&#34;最后有一些额外的字符。在关闭括号之前&#34;})&#34;。
UPD。 Plot2没有出现,因为你在menuItem和tabItem中有不同的标签 - &#34; Fore_Cast&#34;和&#34; Fore_cast&#34;分别
关于Plot1。当我运行应用程序时,我看到了这一点:&#34;错误:对象&#39;日期&#39;找不到&#34;,所以我看了代码输出$ plot1。你用这个: AES(日期,金额,组=过滤()$一年,颜色过滤=()$年) 我更正了filter()$ Date,filtered()$ Amount和plot已经出现。但只有部分
scale_x_date()
被评论。如果我使用&#34; scale_x_date()&#34;,则会出现错误:输入无效:date_trans仅适用于类Date的对象。也许您应该通过mutate方法转换此列。