eprilog/eprilog.r

136 lines
5.3 KiB
R
Raw Normal View History

2024-01-12 18:25:14 +00:00
#################
# Author: PMF #
#################
2024-01-12 13:57:59 +00:00
require(shiny)
2024-01-12 18:25:14 +00:00
# preperation:
2024-01-12 13:57:59 +00:00
# Get the status if r shiny is running in docker or not
readRenviron("./.status-docker")
statusDocker <- Sys.getenv("statusDockerENV")
ui <- navbarPage("EpriLog",
tabPanel("Eprilog",
sidebarLayout(
mainPanel(
h1('Brew History'),
DT::dataTableOutput('history')
),
sidebarPanel(
h1('New Entry'),
dateInput("date", "Date:"), #maybe better to automatically generate with time
2024-01-12 18:25:14 +00:00
selectInput("alias", "Whats the nick name of the coffee?", coffees$alias, multiple = FALSE),
2024-01-12 13:57:59 +00:00
selectInput("coffeeName", "Whats the name of the coffee?", coffees$coffeeName, multiple = FALSE),
# Grind Time
2024-01-12 18:25:14 +00:00
sliderInput("grindTime", "Ginding Time", value = 14, min = 0, max = 30),
2024-01-12 13:57:59 +00:00
# Grind Size
2024-01-12 18:25:14 +00:00
sliderInput("grindSize", "Ginding Size", value = 7, min = 0, max = 70),
2024-01-12 13:57:59 +00:00
# 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
2024-01-12 18:25:14 +00:00
textInput("notes", "Notes:", value = 'Keine Notizen'),
2024-01-12 13:57:59 +00:00
# submit
actionButton("createEntry", "Submit new entry!", icon("save")),
)
)
),
tabPanel("Configuration",
mainPanel(
h1('Add Coffees'),
h3('coming soon!')
)
)
)
server <- function(input, output){
# 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,
2024-01-12 18:25:14 +00:00
options = list(order = list(3, "desc"),
columnDefs = list(list(visible = FALSE, targets = c(1,2,10,11,12,13,14,15,16)))
2024-01-12 14:43:27 +00:00
))
2024-01-12 13:57:59 +00:00
# insert new entry
observeEvent(input$createEntry, {
# get currentTime
currentTime <- Sys.time()
2024-01-12 14:43:27 +00:00
# count up for new brew id
2024-01-12 18:25:14 +00:00
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)
2024-01-12 13:57:59 +00:00
# add new line entry to history
2024-01-12 14:43:27 +00:00
brews[nrow(brews) + 1, 1] <- newID
brews[nrow(brews), 2] <- input$date
brews[nrow(brews), 3] <- currentTime
2024-01-12 18:25:14 +00:00
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
2024-01-12 14:43:27 +00:00
2024-01-12 13:57:59 +00:00
# save changes to .csv file
write.csv(brews, file = "./data/brews.csv")
})
}
if (statusDocker == "false") {
runApp(shinyApp(ui = ui, server = server, options = list(launch.browser = TRUE)))
} else {
shinyApp(ui = ui, server = server)
}