171 lines
6.8 KiB
R
171 lines
6.8 KiB
R
#################
|
|
# Author: PMF #
|
|
#################
|
|
|
|
require(shiny)
|
|
require(DT)
|
|
|
|
# preperation:
|
|
# Get the status if r shiny is running in docker or not
|
|
readRenviron("./.status-docker")
|
|
statusDocker <- Sys.getenv("statusDockerENV")
|
|
|
|
|
|
# loading data from csv files
|
|
brews <- (read.csv(file = "./data/brews.csv", header = TRUE, sep = ",", row.names = 1))
|
|
machines <- read.csv(file = "./data/machines.csv")
|
|
grinders <- read.csv(file = "./data/grinders.csv")
|
|
coffees <- read.csv(file = "./data/coffees.csv")
|
|
|
|
|
|
ui <- navbarPage("EpriLog",
|
|
tabPanel("Brews",
|
|
sidebarLayout(
|
|
mainPanel(
|
|
h1('Brew History'),
|
|
DT::dataTableOutput('history')
|
|
),
|
|
sidebarPanel(
|
|
h1('New Entry'),
|
|
dateInput("date", "Date:"), #maybe better to automatically generate with time
|
|
selectInput("alias", "Whats the nick name of the coffee?", coffees$alias, multiple = FALSE),
|
|
selectInput("coffeeName", "Whats the name of the coffee?", coffees$coffeeName, multiple = FALSE),
|
|
# Grind Time
|
|
sliderInput("grindTime", "Ginding Time", value = 14, min = 0, max = 30),
|
|
# Grind Size
|
|
sliderInput("grindSize", "Ginding Size", value = 7, min = 0, max = 70),
|
|
# Flow rate (0 = none, 10 = perfect, 20 = water)
|
|
sliderInput("flowResult", "Flow rate (10 is Perfect):", value = 10, min = 0, max = 20),
|
|
# Taste Rating (sour = none, 10 = perfect, 20 = bitter)
|
|
sliderInput("taste", "Taste (0=Sour, 10=perfect, 20=bitter):", value = 10, min = 0, max = 20),
|
|
# WDT Tool
|
|
checkboxInput("wdt", "WDT Tool used?", value = TRUE),
|
|
# Brew Temp
|
|
numericInput("brewTemp", "Brew Temperature:", value = 94, min = 0, max = 110),
|
|
# Brew preinfusion time
|
|
numericInput("brewPreinfusion", "Brew Preinfusion Time", value =2, min = 0, max = 60),
|
|
# Brew wait Time after Preinfusion
|
|
numericInput("brewPreinfusionWait", "Brew Wait after Preinfusion Time", value = 5, min = 0, max = 60),
|
|
# Brew Time
|
|
numericInput("brewTime", "Brew Time after Preinfusion Time", value = 21, min = 0, max = 100),
|
|
# Grinder Device
|
|
selectInput("grinderDevice", "Which Grinder was used?", grinders$name, multiple = FALSE),
|
|
# Espresso Device
|
|
selectInput("machineDevice", "Which Espresso machine was used?", machines$name, multiple = FALSE),
|
|
# Siebeinsatz
|
|
numericInput("portaInsert", "Siever insert size", value = 12, min = 0, max = 100),
|
|
# Notes
|
|
textInput("notes", "Notes:", value = "Keine Notizen"),
|
|
# submit
|
|
actionButton("createEntry", "Submit new entry!", icon("save")),
|
|
)
|
|
)
|
|
),
|
|
tabPanel("Configuration",
|
|
sidebarLayout(
|
|
mainPanel(
|
|
h1('Already available Coffees'),
|
|
DT::dataTableOutput('coffees')
|
|
),
|
|
sidebarPanel(
|
|
h2('Add New Coffees'),
|
|
textInput("brandName", "Brand Name", value = ""),
|
|
textInput("coffeeName", "Coffee Name", value = ""),
|
|
textInput("alias", "Nick Name", value = ""),
|
|
dateInput("expDate", "Expiration Date"),
|
|
numericInput("arabicaPercentage", "Arabica Percentage", value = "50"),
|
|
numericInput("robustaPercentage", "Robusta Percentage", value = "50"),
|
|
numericInput("sourPercentage", "Sourness Percentage", value = "50"),
|
|
numericInput("strongnessPercentage", "Strongness Percentage", value = "50"),
|
|
numericInput("roastDarknessPercentage", "Roast Darkness Percentage", value = 50),
|
|
textInput("originCountry", "Origin County of the Coffee", value = "Coffee World"),
|
|
)
|
|
)
|
|
))
|
|
|
|
|
|
server <- function(input, output, session){
|
|
|
|
# loading data from csv files
|
|
brews <- (read.csv(file = "./data/brews.csv", header = TRUE, sep = ",", row.names = 1))
|
|
machines <- read.csv(file = "./data/machines.csv")
|
|
grinders <- read.csv(file = "./data/grinders.csv")
|
|
coffees <- read.csv(file = "./data/coffees.csv")
|
|
|
|
# Render History Table
|
|
output$history = DT::renderDataTable(
|
|
brews, server = TRUE,
|
|
options = list(order = list(3, "desc"),
|
|
list(scrollX = TRUE),
|
|
columnDefs = list(list(visible = FALSE, targets = c(1,2,3,10,11,12,13,14,15,16)))
|
|
))
|
|
|
|
output$coffees = DT::renderDataTable(
|
|
coffees, server = TRUE,
|
|
options = list(scrollX = TRUE)
|
|
#colnames = c("ID", "Brand Name", "Coffee Name", )
|
|
#options = list(order = list(3, "desc")
|
|
#columnDefs = list(list(visible = FALSE, targets = c(1,2,10,11,12,13,14,15,16)))
|
|
)
|
|
|
|
|
|
|
|
# insert new entry
|
|
observeEvent(input$createEntry, {
|
|
# get currentTime
|
|
currentTime <- Sys.time()
|
|
# count up for new brew id
|
|
newID <- (runif(1, 1, 10000000000))
|
|
|
|
# For debugging only
|
|
#
|
|
# print(input$date)
|
|
# print(currentTime)
|
|
# print(input$alias)
|
|
# print(input$coffeeName)
|
|
# print(input$grindTime)
|
|
# print(input$grindSize)
|
|
# print(input$flowResult)
|
|
# print(input$taste)
|
|
# print(input$wdt)
|
|
# print(input$brewTemp)
|
|
# print(input$brewPreinfusion)
|
|
# print(input$brewPreinfusionWait)
|
|
# print(input$brewTime)
|
|
# print(input$grinderDevice)
|
|
# print(input$machineDevice)
|
|
# print(input$portaInsert)
|
|
# print(input$notes)
|
|
|
|
# add new line entry to history
|
|
brews[nrow(brews) + 1, 1] <- newID
|
|
brews[nrow(brews), 2] <- input$date
|
|
brews[nrow(brews), 3] <- currentTime
|
|
brews[nrow(brews), 4] <- input$alias
|
|
brews[nrow(brews), 5] <- input$coffeeName
|
|
brews[nrow(brews), 6] <- input$grindTime
|
|
brews[nrow(brews), 7] <- input$grindSize
|
|
brews[nrow(brews), 8] <- input$flowResult
|
|
brews[nrow(brews), 9] <- input$taste
|
|
brews[nrow(brews), 10] <- input$wdt
|
|
brews[nrow(brews), 11] <- input$brewTemp
|
|
brews[nrow(brews), 12] <- input$brewPreinfusion
|
|
brews[nrow(brews), 13] <- input$brewPreinfusionWait
|
|
brews[nrow(brews), 14] <- input$brewTime
|
|
brews[nrow(brews), 15] <- input$grinderDevice
|
|
brews[nrow(brews), 16] <- input$machineDevice
|
|
brews[nrow(brews), 17] <- input$portaInsert
|
|
brews[nrow(brews), 18] <- input$notes
|
|
|
|
# save changes to .csv file
|
|
write.csv(brews, file = "./data/brews.csv")
|
|
session$reload()
|
|
})
|
|
|
|
}
|
|
|
|
if (statusDocker == "false") {
|
|
runApp(shinyApp(ui = ui, server = server, options = list(launch.browser = TRUE)))
|
|
} else {
|
|
shinyApp(ui = ui, server = server)
|
|
} |