Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. library(rhandsontable)
  2. library(shiny)
  3. DF <- data.frame(
  4. ######Logistic ent.
  5.  
  6.  
  7.  
  8. "project number" = c(NA, ''),
  9. "project name" = c(NA, ''),
  10. "description" = c(''),
  11.  
  12. "estimated delivery date" = seq(from = Sys.Date(), by = "days", length.out = 10),
  13. "actual delivery date" =seq(from = Sys.Date(), by = "days", length.out = 10),
  14.  
  15.  
  16. "current status " = c(''),
  17. "note" = c(''),
  18.  
  19.  
  20.  
  21.  
  22. "GA status" = factor(NA, c('approved','awaiting','no needed')),
  23.  
  24.  
  25. "GA hours" = c(''),
  26. "GA actual" = c(''),
  27.  
  28. "SSEC hours" = c(''),
  29. "SSEC actual" = c(''),
  30.  
  31. "steel hours" = c(''),
  32. "steel actual" = c(''),
  33.  
  34. "steel drawing sent" = FALSE,
  35. "steel drawing date" = seq(from = Sys.Date(), by = "days", length.out = 10),
  36.  
  37. "tarp hours" = c(''),
  38. "tarp actual" = c(''),
  39.  
  40. "tarp drawing sent" = FALSE,
  41. "tarp drawing date" = seq(from = Sys.Date(), by = "days", length.out = 10),
  42.  
  43.  
  44. "installation hours " = c(''),
  45. "installation actual " = c(''),
  46.  
  47. ###############Phil Rob
  48.  
  49. "generate component list " = FALSE,
  50. "drawings checked"= FALSE,
  51.  
  52. ########alex fabrication part
  53.  
  54.  
  55.  
  56. "tarp drawing" = FALSE,
  57. "estimated completion date"= c(''),
  58. "material"= factor(NA, c("Armourtex", "Landmark", "Armourtex FR", "Armourtex White/Silver")),
  59. "drawing availability date"= c(''),
  60. "tarp production status" = c(""),
  61.  
  62. "estimated completion date" = c(""),
  63.  
  64. "estimated completion date" = c(""),
  65.  
  66.  
  67.  
  68. ######################### JIM STEEL
  69.  
  70.  
  71.  
  72.  
  73. "drawing availability date" = c(""),
  74.  
  75. "rolling group" = c(""),
  76. "rolling date" = c(""),
  77. "Hoop group" = c(""),
  78. "Hoop date" = c(""),
  79. "mountain rail group" = c(""),
  80. "mountain rail date" = c(""),
  81.  
  82.  
  83. "P-B group" = c(""),
  84. "P-B date" = c(""),
  85. "Posts group" = c(""),
  86. "Posts date" = c(""),
  87. "Endwall group" = c(""),
  88. "Endwall date" = c(""),
  89. "galv sent date" = seq(from = Sys.Date(), by = "days", length.out = 10),
  90. "galv return date" = seq(from = Sys.Date(), by = "days", length.out = 10),
  91.  
  92.  
  93. ##########logistic
  94.  
  95. "tarp received" = FALSE,
  96. "steel received" = FALSE,
  97. "instruction list" = FALSE,
  98. "packing" = FALSE,
  99. "delivery target date" = seq(from = Sys.Date(), by = "days", length.out = 1),
  100. "project comment" = c(""),
  101.  
  102. registered = c(TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE),
  103. stringsAsFactors = FALSE, check.names = FALSE)
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. ui <- shinyUI(fluidPage(
  120.  
  121. titlePanel("Edit and save a table"),
  122. sidebarLayout(
  123. sidebarPanel(
  124. helpText("Shiny app based on an example given in the rhandsontable package.",
  125. "Right-click on the table to delete/insert rows.",
  126. "Double-click on a cell to edit"),
  127.  
  128. wellPanel(
  129. h3("Table options"),
  130. radioButtons("useType", "Use Data Types", c("TRUE", "FALSE"))
  131. ),
  132. br(),
  133.  
  134. wellPanel(
  135. h3("Save table"),
  136. div(class='row',
  137. div(class="col-sm-6",
  138. actionButton("save", "Save")),
  139. div(class="col-sm-6",
  140. radioButtons("fileType", "File type", c("ASCII", "RDS")))
  141. )
  142. )
  143.  
  144. ),
  145.  
  146. mainPanel(
  147. wellPanel(
  148. uiOutput("message", inline=TRUE)
  149. ),
  150.  
  151. actionButton("cancel", "Cancel last action"),
  152. br(), br(),
  153.  
  154. rHandsontableOutput("hot"),
  155. br(),
  156.  
  157. wellPanel(
  158. h3("Add a column"),
  159. div(class='row',
  160. div(class="col-sm-5",
  161. uiOutput("ui_newcolname"),
  162. actionButton("addcolumn", "Add")),
  163. div(class="col-sm-4",
  164. radioButtons("newcolumntype", "Type", c("integer", "double", "character"))),
  165. div(class="col-sm-3")
  166. )
  167. )
  168.  
  169. )
  170. )
  171. ))
  172.  
  173. server <- shinyServer(function(input, output) {
  174.  
  175. values <- reactiveValues()
  176.  
  177. ## Handsontable
  178. observe({
  179. if (!is.null(input$hot)) {
  180. values[["previous"]] <- isolate(values[["DF"]])
  181. DF = hot_to_r(input$hot)
  182. } else {
  183. if (is.null(values[["DF"]]))
  184. DF <- DF
  185. else
  186. DF <- values[["DF"]]
  187. }
  188. values[["DF"]] <- DF
  189. })
  190.  
  191. output$hot <- renderRHandsontable({
  192. DF <- values[["DF"]]
  193. if (!is.null(DF))
  194. rhandsontable(DF, useTypes = as.logical(input$useType), stretchH = "all")
  195. })
  196.  
  197. ## Save
  198. observeEvent(input$save, {
  199. fileType <- isolate(input$fileType)
  200. finalDF <- isolate(values[["DF"]])
  201. if(fileType == "ASCII"){
  202. dput(finalDF, file=file.path(outdir, sprintf("%s.txt", outfilename)))
  203. }
  204. else{
  205. saveRDS(finalDF, file=file.path(outdir, sprintf("%s.rds", outfilename)))
  206. }
  207. }
  208. )
  209.  
  210. ## Cancel last action
  211. observeEvent(input$cancel, {
  212. if(!is.null(isolate(values[["previous"]]))) values[["DF"]] <- isolate(values[["previous"]])
  213. })
  214.  
  215. ## Add column
  216. output$ui_newcolname <- renderUI({
  217. textInput("newcolumnname", "Name", sprintf("newcol%s", 1+ncol(values[["DF"]])))
  218. })
  219. observeEvent(input$addcolumn, {
  220. DF <- isolate(values[["DF"]])
  221. values[["previous"]] <- DF
  222. newcolumn <- eval(parse(text=sprintf('%s(nrow(DF))', isolate(input$newcolumntype))))
  223. values[["DF"]] <- setNames(cbind(DF, newcolumn, stringsAsFactors=FALSE), c(names(DF), isolate(input$newcolumnname)))
  224. })
  225.  
  226. ## Message
  227. output$message <- renderUI({
  228. if(input$save==0){
  229. helpText(sprintf("This table will be saved in folder \"%s\" once you press the Save button.", outdir))
  230. }else{
  231. outfile <- ifelse(isolate(input$fileType)=="ASCII", "table.txt", "table.rds")
  232. fun <- ifelse(isolate(input$fileType)=="ASCII", "dget", "readRDS")
  233. list(helpText(sprintf("File saved: \"%s\".", file.path(outdir, outfile))),
  234. helpText(sprintf("Type %s(\"%s\") to get it.", fun, outfile)))
  235. }
  236. })
  237.  
  238. })
  239.  
  240. ## run app
  241. runApp(list(ui=ui, server=server))
  242. return(invisible())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement