我的问题与“value4”有关,它是下面代码中的一个值框。
我创建了一个选择输入,允许用户根据该名称选择一个名称,我希望应用程序找到与所选名称关联的项目数(项目数 =“X..setup”),然后在 valuebox("value4") 中显示项目总数。
我遇到的问题是获得所有项目的总和。请在下面找到我的代码:
setups <- read.csv("C:/Users/obria/Desktop/setUps/setUp.csv",stringsAsFactors = F, header = TRUE)
View(setups)
head(setups)
searchDF <- setups[c(1,2,3,4,7,8,9,10,11)]
#lst.Owners <- as.list(unique(setups$Owners))
lst.Owners = as.character(setups$Owners)
Owners <- unique(lst.Owners)
userInput <- sum(str_count(setups$Over.all.Status.of.Project,"WIP")) %>% groub_by(Owners)
install.packages("dplyr")
install.packages("ggplot2")
library(ggplot2)
library(dplyr)
library(shiny)
library(shinydashboard)
library(stringr)
library (DT)
ui = dashboardPage(
#Header
dashboardHeader(title = "Set ups dashboard"),
#Sidebar
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard"),
menuItem("Search", tabName = "search"),
menuItem("Break Down", tabName = "breakDown")
)
),
#Body
dashboardBody(tabItems(
# First tab content
tabItem(tabName = "dashboard",
fluidRow(
valueBoxOutput("value1")
,valueBoxOutput("value2")
,valueBoxOutput("value3"),
fluidRow(
box(
title= "Owner Vs Set Ups"
,status = "primary"
,solidheader = TRUE
,collapsible = TRUE
,plotOutput("nameStatus", height = "300px")
)
,box(
title= " Pant Vs Set Ups"
,status = "primary"
,solidheader = TRUE
,collapsible = TRUE
,plotOutput("plantSetUps", height = "300px"))))
),
# Second tab content #
tabItem(tabName = "search",
fluidRow(
h2("Search Set ups"),
DT::dataTableOutput("mytable")
)),
# Third tab content #
tabItem(tabName = "breakDown",
h2("Search Set ups"),
fluidRow(
box(
selectInput("selectVariable", "Select Variable:",
choices = Owners,
selected = 1))),
fluidRow(
valueBoxOutput("value4")
))))
)
server = function(input, output) {
# Get some data #
# Total Set ups #
totalSetUps <- sum(setups$X..setups)
# Number of WIPs #
workIP1 <- sum(str_count(setups$Over.all.Status.of.Project,"WIP"))
workIP2 <- sum(str_count(setups$Over.all.Status.of.Project,"wip"))
workInProgress <- (workIP1 + workIP2)
# Number of Outstanding #
outstanding <- sum(str_count(setups$Over.all.Status.of.Project,"Outstanding"))
# Colonia - Test Val;ue box #
#colonia <- sum(str_count(setups$Plant,"Colonia"))
setUpByName <- reactive ({
setups %>%
filter(Owners == input$selectVariable) %>%
sum(.$X..setups)
})
# Create the valueBoxOutput Content #
output$value1 <- renderValueBox({
valueBox(
format(totalSetUps, format="d", big.mark=",")
,"Total Number of Set Ups"
,icon = icon("stats",lib="glyphicon")
,color = "purple")
})
output$value2 <- renderValueBox({
valueBox(
format(workInProgress, format="d", big.mark=",")
,"No. of project that are WIP"
,icon = icon("gbp",lib="glyphicon")
,color = "green")
})
output$value3 <- renderValueBox({
valueBox(
format(outstanding, format="d", big.mark=",")
,"No. of project that are Outstanding"
,icon = icon("menu-hamburger",lib="glyphicon")
,color = "yellow")
})
output$value4 <- renderValueBox({
valueBox(
format(setUpByName(), format="d", big.mark=",")
,"total # Set ups"
,icon = icon("menu-hamburger",lib="glyphicon")
,color = "yellow")
})
# Creating plot output content #
output$nameStatus <- renderPlot({
ggplot(data = setups,
aes(x=setups$Owners, y=setups$X..setup, fill=factor(Over.all.Status.of.Project))) +
geom_bar(position = "dodge", stat = "identity") + ylab("No. of Set ups") +
xlab("Owners") + theme(legend.position="bottom"
,plot.title = element_text(size=15, face="bold")) +
ggtitle("Owners vs No. of Set Ups") + labs(fill = "Status")
})
output$plantSetUps <- renderPlot({
ggplot(data=setups, aes(x=setups$Plant, y= setups$X..setup)) +
geom_bar(stat="identity", col="blue", fill="blue") +
labs(title ="No of Set ups by plant")
})
output$mytable = DT::renderDataTable({
setups
})
output$result <- renderText({
paste("You chose", input$selectVariable)
})
}
shinyApp(ui, server)
str(setups)
任何帮助将不胜感激。谢谢