微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何制作面板以在 r markdown/runtime 闪亮中显示/隐藏反应数据表? 选择日期范围选择店铺日期分析

如何解决如何制作面板以在 r markdown/runtime 闪亮中显示/隐藏反应数据表? 选择日期范围选择店铺日期分析

从以下链接读取/下载 csv 文件 https://github.com/ANUJGULATI93/rrr 谢谢

---
title: " Analysis"
output: 
  html_notebook: 
    toc: yes
    toc_float: true
  html_document: 
    number_sections: yes
    runtime: shiny
--- 
library(ggplot2)
# library(bsselectR)
library(rmarkdown)
library(shiny)
library(readxl)
library(prospectr)
library(openxlsx)
library(ggpubr)
library(tidyverse)
library(broom)
library(shinyjs)
library(shinydashboard)
library(nortest)
library(WRS2)
library(car)
library(dplyr)
library(fmsb)
library(factoextra)
library(plotly)
library(lubridate)
library(forcats)
library(rstatix)
library(Rtsne)
library(cluster)
library(tibble)
library(qcc)
library(ggQC)
library(ggpmisc)
library(rockchalk)
library(tidyr)
library(reshape2)
library(janitor)
library(flextable)
library(officer)
library(DT)
library(shiny)
rm(list = ls())
options(max.print=1000000)

# setwd("C:/Users/Anuj Gulati/Documents/specdata")
# dev.off()
df<-read.csv("Book1.csv",colClasses = c("factor","factor","numeric","factor"))
df<-df[!(df$Machine)=="N/A",]
df<-df[!(df$Machine)=="",]
df<-df[!(df$Actual.Kg< 5),]
df<-df[!(df$Product.code=="Nil"),]
df<-df[!(df$Product.code=="Nil 0"),]
df<-df[!(df$Product.code==""),]
df<-df[!(df$Slow.Speed..< 1),]
df<-df[!(df$Shift==""),]
df<-df[!(df$Down.Time.. ==0),]
df<-df[!(df$Operator=="Sales Training"),]
df<-df[!(df$Operator=="Sales Trainee"),]
df<-df[!(df$Operator=="Sales_trainee"),]
df<-df[!(df$Operator==""),]
df<-df[!(df$Operator=="N/A"),]
df<-df[(df$Calculated.kg>=0),]
levels(df$Machine)[levels(df$Machine)=="spooling 12"] <- "Spooling 12"
levels(df$Area)[levels(df$Area)=="dd"] <- "Dry Draw"
levels(df$Area)[levels(df$Area)=="wd"] <- "Wet Draw"
levels(df$Area)[levels(df$Area)=="saw"] <- "Submerged Arc"
# levels(df$Area)[levels(df$Area)=="drumming"] <- "Dry Draw"
# levels(df$Area)[levels(df$Area)=="dd"] <- "Dry Draw"
# dashboardPage(dashboardHeader(title = "Downtime"),dashboardSidebar(),dashboardBody())

df$Shift<-factor(df$Shift)
df$Machine<-factor(df$Machine)
my_reason_dataframe<-read.csv("master_reason.csv","factor"))
my_reason_dataframe<-my_reason_dataframe[!(my_reason_dataframe$Shift==""),]
my_reason_dataframe<-my_reason_dataframe[!(my_reason_dataframe$Reason=="no plan"),]
my_reason_dataframe<-my_reason_dataframe[!(my_reason_dataframe$Machine=="N/A"),]
my_reason_dataframe<-my_reason_dataframe[!(my_reason_dataframe$Operator ==""),]
my_reason_dataframe<-my_reason_dataframe[!(my_reason_dataframe$Operator=="N/A"),]
my_reason_dataframe<-my_reason_dataframe[!(my_reason_dataframe$Operator=="Sales_trainee"),]
my_reason_dataframe<-my_reason_dataframe[!(my_reason_dataframe$Operator=="Sales Trainee"),]
my_reason_dataframe<-my_reason_dataframe[!(my_reason_dataframe$Operator=="Sales Training"),]
my_reason_dataframe<-my_reason_dataframe[!(my_reason_dataframe$Product.code=="Nil"),]
my_reason_dataframe<-my_reason_dataframe[!(my_reason_dataframe$Product.code=="Nil 0"),]
reason_Pop<-my_reason_dataframe
 my_reason_dataframe$Date<-dmy(my_reason_dataframe$Date)
levels(my_reason_dataframe$Area)[levels(my_reason_dataframe$Area)=="dd"] <- "Dry Draw"
levels(my_reason_dataframe$Area)[levels(my_reason_dataframe$Area)=="wd"] <- "Wet Draw"
levels(my_reason_dataframe$Area)[levels(my_reason_dataframe$Area)=="saw"] <- "Submerged Arc"


选择日期范围

Pop<-df
daterangeInput("daterange3","Date range:",start = "2020-10-01",end="2020-10-31",min = "2020-10-01",max =Sys.Date(),format = "dd/mm/yy",separator = " - ")
df$Date<-dmy(df$Date)
df<-df[order(df$Date),]
reactive_df<-reactive({df%>%filter(Date >= input$daterange3[1] & Date <= input$daterange3[2])
})
reactive_reason_df<-reactive({my_reason_dataframe%>%filter(Date >= input$daterange3[1] & Date <= input$daterange3[2])
})


# renderDT({
#   datatable(reactive_df())
# })
# strong("Analysis for All Shops in the selected timeframe") 
# dashboardPage(dashboardHeader(),dashboardBody(),title = "Downtime")
my_shops_reactive<-reactive({
  group_by(reactive_df(),Area) %>%
  summarise(
    `Shop Count` = n(),`Avg Downtime%` = round(mean(Down.Time..,na.rm = TRUE),2),`Std Dev` = round(sd(Down.Time..,2)
       )
})
dd_reactive<-reactive({
  filter(reactive_df(),Area=="Dry Draw")
  })
dd_reactive_dt<-reactive({

  dd_t_test<-t.test(dd_reactive()[,10],dd$Down.Time..,alternative="greater")
  return(round(dd_t_test$`p.value`,2))
})

drum_reactive<-reactive({
  filter(reactive_df(),Area=="drumming")
  })
drum_reactive_dt<-reactive({
  drum_t_test<-t.test(drum_reactive()[,drum$Down.Time..,alternative="greater")
  return(round(drum_t_test$`p.value`,2))
         })

saw_reactive<-reactive({
  filter(reactive_df(),Area=="Submerged Arc")
  })
saw_reactive_dt<-reactive({

  saw_t_test<-t.test(saw_reactive()[,saw$Down.Time..,alternative="greater")
  return(round(saw_t_test$`p.value`,2))
})
spool_reactive<-reactive({
  filter(reactive_df(),Area=="spooling")
  })
spool_reactive_dt<-reactive({
  spool_t_test<-t.test(spool_reactive()[,spool$Down.Time..,alternative="greater")
  return(round(spool_t_test$`p.value`,2))
})

wd_reactive<-reactive({
  filter(reactive_df(),Area=="Wet Draw")
  })
# renderDT({
#   wd_reactive()
# })
wd_reactive_dt<-reactive({
  wd_t_test<-t.test(wd_reactive()[,wd$Down.Time..,alternative="greater")
  return(round(wd_t_test$`p.value`,2))
})
`P values`<-reactive({
  rbind(dd_reactive_dt(),drum_reactive_dt(),saw_reactive_dt(),spool_reactive_dt(),wd_reactive_dt())
 })
# renderDT({
#   my_p()
# })
pop_mean_shop<-aggregate(Down.Time..~Area,df,mean)

pop_mean_add_to_df<-reactive({
 
  cbind(my_shops_reactive(),`Pop Mean`=round(pop_mean_shop$Down.Time..,2))
})
my_p_value_reactive<-reactive({
  cbind(pop_mean_add_to_df(),`P values`=`P values`())
})
# renderDT({
#   my_p_value_reactive()
# })
shops_filter<-reactive({
  # filter_shops<-
    my_p_value_reactive() %>% filter(`Std Dev`>15|`P values`<0.05 )
        
  })
  # if (nrow(filter_shops)>0) {
  #   # cat(" For Selected Timeframe,these Shops are LOW Performing for Downtime%:","\n")
  #   x<-unlist(filter_shops$Area)
  #   for (i in 1:nrow(filter_shops)) {
  #          cat(as.character(x[i])," Shop is Performing Inconsistently in this timeframe","\n")
  #     
  #   }
  #    
  #  }else{k=0}
  # # |`P values`<0.05
  # 
  # })
# p('For this Timeframe,these Shops are LOW Performing for Downtime%:')
renderPrint({
cat(" For this Timeframe,these Shops are LOW Performing for Downtime%:")
  # p(as.character(shops_filter()$Area),sep=",")
  shop()
    })
shop<-reactive({
if(nrow(shops_filter()>0)){ 
      cat(as.character(shops_filter()$Area),")
}else{cat("No Low Performing Shops in this timeframe")}

})
max_std_shop<-reactive({
 std_shop<-shops_filter()%>% filter(`Std Dev`>15)
    p<-max(std_shop$`Std Dev`)
  max_std_shop<-std_shop%>% filter(`Std Dev`==p)
  # shift<-as.character(max_std_shift$Shift)
  if(nrow(max_std_shop) > 0){
  cat(as.character(max_std_shop$Area),"shop is inconsistently performing in Downtime% ")
    }else{k=0}
  
})
renderPrint({
  max_std_shop()
  })
pv_shop<-reactive({
  p_v<-shops_filter()%>%filter(`P values`< 0.05)
  if (nrow(p_v)>0){  
    x<-unlist(p_v$Area)
    j<-unlist(p_v$`Pop Mean`)
    k<-unlist(p_v$`Avg Downtime%` )
    cat("For this Timeframe,Shops with 'Avg. %Downtime' more than the 'Avg. %Downtime of past data' are:","\n")
    for (i in 1:nrow(p_v)) {
      inc_dt<-round(((k[i]-j[i])/j[i])*100,2)
    cat(as.character(x[i]),"shop has",as.numeric(inc_dt),"% increase in Downtime% ","\n" ) 
    }
    
  }else{k=0}
  })  
renderPrint({
  pv_shop()
  
})
shops_html<-reactive({ 
datatable(shops_filter(),rownames = TRUE,caption = htmltools::tags$caption("LOW Performing Shops ",style="font-weight:bold;color:black"),class = 'cell-border strip hover',options = list(dom='t',pageLength=10)) %>%
formatStyle(0,cursor = 'pointer')%>%
  formatStyle(columns = "Std Dev",background = styleInterval(c(15),c("NULL","red"))) %>%
    formatStyle(columns = "P values",background = styleInterval(c(0.051),c("red","NULL")))
})

renderDT({
  shops_html()
})
# shiny::addResourcePath('www',here::here("www"))
# renderDT({
#   datatable(my_shops_reactive())
# })

# my_shops_reactive<-reactiveVal()
# my_shops_reactive()


# pvalue_shops_reactive()$shops_pop_filter
# renderDT({
#   datatable(pvalues())
# })
# UCL<-reactive({
#   my_shifts()$Mean+my_shifts()$`Std Dev`
# })
# add_to_df <- reactive({
#         cbind(my_shifts(),UCL())
#               })

# Pop_dd<-Pop[Pop$Area=="dd",]
# Pop_saw<-Pop[Pop$Area=="saw",]
# Pop_drumming<-Pop[Pop$Area=="drumming",]
# Pop_spool<-Pop[Pop$Area=="spooling",]
# 
# # Population of Wet Draw Machines
# Pop_wd<-Pop[Pop$Area=="wd",]
# 
# # Filtering dataset into date range
# df$Date<-dmy(df$Date)
# DATE1 <- as.Date("2020-11-01")
# DATE2 <- as.Date("2020-11-30")
# dates <- seq(DATE1,DATE2,by="days")
# 
# df <- subset(df,Date %in% dates)
# df_ungroup<-df[,c(3,10)]
# 
# # model<-aov(Down.Time..~Area,df)
# # anova(model)
# 
wd<-filter(Pop,Area=="Wet Draw")
dd<-filter(Pop,Area=="Dry Draw")
saw<-filter(Pop,Area=="Submerged Arc")
drum<-filter(Pop,Area=="drumming")
spool<-filter(Pop,Area=="spooling")
Shift_A_pop<-filter(Pop,Shift=="A")
Shift_B_pop<-filter(Pop,Shift=="B")
Shift_C_pop<-filter(Pop,Shift=="C")
WD1<-filter(Pop,Machine=="Wet Draw 1")
WD2<-filter(Pop,Machine=="Wet Draw 2")
WD3<-filter(Pop,Machine=="Wet Draw 3")
WD4<-filter(Pop,Machine=="Wet Draw 4")
WD5<-filter(Pop,Machine=="Wet Draw 5")
WD6<-filter(Pop,Machine=="Wet Draw 6")
WD8<-filter(Pop,Machine=="Wet Draw 8")
WD9<-filter(Pop,Machine=="Wet Draw 9")
WD10<-filter(Pop,Machine=="Wet Draw 10")
WD11<-filter(Pop,Machine=="Wet Draw 11")
WD12<-filter(Pop,Machine=="Wet Draw 12")


选择店铺


all_shops<-c("Dry Draw","Wet Draw","spooling","Submerged Arc","drumming")

selectInput("my shops","Shops",choices =all_shops,selected="NULL")
# #  Choosing Shops
my_data<-reactive({
  filter(reactive_df(),Area %in% input$`my shops`)
   
})
my_data_pop<-reactive({
  my_data()
})
my_shop_data<-reactive({
  filter(df,Area %in% input$`my shops`)

})
avg_dt_perc_reactive<-reactive({
  group_by(my_data(),Date)%>%
    summarise(
    # Mean = round(mean(Down.Time..,# `Std Dev` = round(sd(Down.Time..,`Avg. DownTime%`= round(mean(Down.Time..,2)
      )
  })
my_reason_data<-reactive({
  filter(reactive_reason_df(),Area %in% input$`my shops`)

})
# renderDT({
#   my_shop_data()
# })

# renderDT({
#   
#   my_data()
# })
# date_pop_ucl<-reactive({
#   q=mean(my_data_pop()$Down.Time..)+sd(my_data_pop()$Down.Time..)
#   my_data_pop() %>% add_column(`Timeframe UCL of DT% `=round(q,2))
#  
# })
# renderDT({
# 
#   date_pop_ucl()[,c(1,20)]
# })

日期分析


# strong("Analysis for Dates in this timeframe") 
# renderDT({
#   avg_dt_perc_reactive()
# })
# avg_dt_perc_reactive_new<-reactive({
#   avg_dt_perc_reactive%>%add_column('Timeframe UCL of DT% '=date_pop_ucl())
# })
# renderDT({
#   avg_dt_perc_reactive_new()
# })

my_dates<-reactive({
  q=mean(my_data_pop()$Down.Time..)+sd(my_data_pop()$Down.Time..)
  filter(avg_dt_perc_reactive(),`Avg. DownTime%`> q)
 })
filter_dates<-reactive({
  if (nrow(my_dates())>0) {
  cat("For this Shop,Avg. Downtime% on following Dates is more than 'UCL of this timeframe':")
    
  } else{cat("No LOW Performing Dates")}
})
renderPrint({
  filter_dates()
})
# renderPrint({
#   cat("Following Dates have Avg. Downtime% more than Avg. Downtime%  for the selected Timeframe :")
#   
# })

# renderText({
#   
# })
# wellPanel(
#     helpText(   a("Click Here to Download Survey",href="http://www.dfcm.utoronto.ca/Assets/DFCM2+Digital+Assets/Family+and+Community+Medicine/DFCM+Digital+Assets/Faculty+$!26+Staff/DFCM+Faculty+Work+$!26+leadership+Survey+Poster.pdf",target="_blank")
#     )
#     )
# renderDT({
#     datatable(my_dates(),pageLength=15))
# })

    ```
    <details>
       <summary>Dates</summary>
    ```{r chunk-dt,echo=FALSE,results='hold'}
    renderDT({
     if (nrow(my_dates())>0) {
          datatable(my_dates(),pageLength=15),class                                         = 'cell-border strip hover')%>% 
          formatStyle(0,cursor = 'pointer')
    }
        })

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?