aephidayatuloh commited on
Commit
aafec2f
·
1 Parent(s): fc8ce0a

change to mobile-friendly only using shinyMobile Framework7

Browse files
Files changed (1) hide show
  1. app.R +343 -228
app.R CHANGED
@@ -1,4 +1,5 @@
1
  library(shiny)
 
2
  library(shinyalert)
3
  library(shinyWidgets)
4
  library(glue)
@@ -6,67 +7,143 @@ library(dplyr)
6
  library(dbplyr)
7
  library(stringr)
8
 
9
- # source("dbconnect.R")
10
- # menu <- pg_con |>
11
- # dbReadTable("menu") |>
12
- # mutate(across(karbo:gejala, ~if_else(.x == "", "-", .x)))
13
- # dbDisconnect(pg_con)
14
-
15
- ui <- fluidPage(
16
- h2("SIMPASI Ibrahim"),
17
- # br(),
18
- tabsetPanel(
19
- tabPanel("Input Menu",
20
- br(),
21
- # selectInput("anak", "Anak", choices = c("Ara", "Ibrahim")),
22
- dateInput("tgl", "Tanggal", width = "100%"),
23
- textInput("karbo", "Karbohidrat", width = "100%"),
24
- textInput("protein_hewani", "Protein Hewani", width = "100%"),
25
- textInput("protein_nabati", "Protein Nabati", width = "100%"),
26
- textInput("buah_sayur", "Buah/Sayur", width = "100%"),
27
- textInput("lemak_tambahan", "Lemak Tambahan", width = "100%"),
28
- textAreaInput("camilan", "Camilan", width = "100%"),
29
- textAreaInput("gejala", "Gejala Alergi", width = "100%"),
30
- dateInput("tgl_gejala", "Tanggal Terjadi Gejala", width = "100%"),
31
- actionButton("save", "Simpan", icon = icon("paper-plane"), width = "100%"),
32
- br(),
33
- helpText("Copyright (C) Aep Hidayatuloh 2024", style = "text-align: center")
34
- ),
35
- tabPanel("Cari Catatan",
36
- br(),
37
- selectInput("komponen", "Cari berdasarkan:", width = "100%",
38
- choices = list("Tanggal" = "tanggal", "Karbohidrat" = "karbo", "Protein Hewani" = "protein_hewani", "Protein Nabati" = "protein_nabati", "Buah/Sayur" = "buah_sayur", "Lemak Tambahan" = "lemak_tambahan", "Camilan" = "camilan", "Gejala Alergi" = "gejala")),
39
- conditionalPanel("input.komponen == 'tanggal'",
40
- div(style="display:flex;margin:auto 0px;",
41
- # column(1,
42
- actionButton("prev", "<", style="width:5rem;height:3.4rem;"),
43
- # ),
44
- # column(1,
45
- airDatepickerInput("cari_date", NULL, width = "100%", value = Sys.Date()),
46
- # ),
47
- # column(1,
48
- actionButton("nex", ">", style="width:5rem;height:3.4rem;")
49
- # )
50
- ),
51
- # column(12,
52
- wellPanel(style="background-color:transparent;",
53
- uiOutput("out_cari_tgl")
54
- )
55
- # )
56
- ),
57
- conditionalPanel("input.komponen != 'tanggal'",
58
- textInput("keyword", "Kata kunci", width = "100%"),
59
- # column(12,
60
- uiOutput("out_cari_komponen")
61
- # )
62
- )
63
- ),
64
- tabPanel("Edit Gejala",
65
- br(),
66
- dateInput("edit_tgl_gejala", "Tanggal Terjadi Gejala", width = "100%"),
67
- textInput("edit_gejala", "Gejala Alergi", width = "100%"),
68
- dateInput("edit_tanggal", "Tanggal Pemberian MPASI", width = "100%"),
69
- actionButton("update_edit", "Update", icon = icon("paper-plane"), width = "100%")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  )
71
  )
72
  )
@@ -82,252 +159,290 @@ server <- function(input, output, session){
82
  })
83
 
84
  observeEvent(input$save, {
85
- shinyalert(text = "Yakin ingin menyimpan?", type = "info", showCancelButton = TRUE,
86
  callbackR = function(x){
87
  if(x != FALSE){
88
  shinyalert(text = "Menyimpan data ...", type = "info", showConfirmButton = FALSE, closeOnEsc = FALSE, closeOnClickOutside = FALSE)
89
  tgl_gejala <- if_else(input$gejala %in% c(NA, NULL, "", "-"), NA , as.Date(input$tgl_gejala))
90
-
91
  # source("dbconnect.R")
92
- # query <- glue("INSERT INTO public.menu (id_parent, id_anak, tanggal, karbo, protein_hewani, protein_nabati, buah_sayur, lemak_tambahan, camilan, gejala, tgl_gejala, created_date)
93
  # VALUES (1, 2, '{input$tgl}', '{input$karbo}', '{input$protein_hewani}', '{input$protein_nabati}', '{input$buah_sayur}', '{input$lemak_tambahan}', '{input$camilan}', '{input$gejala}', {tgl_gejala}, '{Sys.time()}')")
94
  menu_data <- tribble(
95
- ~id_parent, ~id_anak, ~tanggal, ~karbo, ~protein_hewani, ~protein_nabati, ~buah_sayur, ~lemak_tambahan, ~camilan, ~gejala, ~tgl_gejala, ~created_date,
96
  1, 2, input$tgl, input$karbo, input$protein_hewani, input$protein_nabati, input$buah_sayur, input$lemak_tambahan, input$camilan, input$gejala, tgl_gejala, Sys.time()
97
  )
98
-
99
- pg_con |>
100
  dbAppendTable(name = "menu", value = menu_data)
101
  # dbDisconnect(pg_con)
102
- updateTextInput(session, "karbo", "Karbohidrat", value = "")
103
- updateTextInput(session, "protein_hewani", "Protein Hewani", value = "")
104
- updateTextInput(session, "protein_nabati", "Protein Nabati", value = "")
105
- updateTextInput(session, "buah_sayur", "Buah/Sayur", value = "")
106
- updateTextInput(session, "lemak_tambahan", "Lemak Tambahan", value = "")
107
- updateTextAreaInput(session, "camilan", "Camilan", value = "")
108
- updateTextAreaInput(session, "gejala", "Gejala Alergi", value = "")
109
- updateDateInput(session, "tgl_gejala", "Tanggal Terjadi Gejala", value = Sys.Date())
 
110
  # closeAlert()
111
  shinyalert(text = "Data berhasil disimpan.", type = "success", immediate = TRUE)
112
-
113
  }
114
  })
115
  })
116
-
117
  observeEvent(input$prev, {
118
  date_val <- reactiveValues()
119
  date_val$curr_dt <- input$cari_date
120
- updateAirDateInput(session, "cari_date", NULL, value = date_val$curr_dt - 1)
121
- }
122
  )
123
-
124
  observeEvent(input$nex, {
125
  date_val <- reactiveValues()
126
  date_val$curr_dt <- input$cari_date
127
- updateAirDateInput(session, "cari_date", NULL, value = date_val$curr_dt + 1)
128
  }
129
  )
130
-
131
  observeEvent(input$prev_history, {
132
- date_val <- reactiveValues()
133
- date_val$curr_dt_history <- input$history_date
134
- updateAirDateInput(session, "history_date", NULL, value = date_val$curr_dt_history - 1)
135
  }
136
  )
137
-
138
  observeEvent(input$nex_history, {
139
- date_val <- reactiveValues()
140
- date_val$curr_dt_history <- input$history_date
141
- updateAirDateInput(session, "history_date", NULL, value = date_val$curr_dt_history + 1)
 
 
 
142
  }
143
  )
144
 
145
  output$out_cari_tgl <- renderUI({
146
- cari_menu <- menu_tbl() |>
147
  collect() |>
148
- mutate(across(karbo:gejala, ~if_else(.x == "", "-", .x))) |>
149
- filter(tanggal == input$cari_date) |>
150
  mutate(tgl_gejala = tgl_gejala |> as.Date() |> format("%d %b %Y"))
151
-
152
  if(nrow(cari_menu) == 0){
153
  p("Tidak ada catatan", style="text-align: center;")
154
  } else {
155
- tagList(
156
- h5("Tanggal"),
157
- h4(format(input$cari_date, "%d %b %Y"), style="margin: 5px 0px 20px;"),
158
- # br(),
159
- h5("Karbohidrat"),
160
- h4(cari_menu$karbo, style="margin: 5px 0px 20px;"),
161
- # br(),
162
- h5("Protein Hewani"),
163
- h4(cari_menu$protein_hewani, style="margin: 5px 0px 20px;"),
164
- # br(),
165
- h5("Protein Nabati"),
166
- h4(cari_menu$protein_nabati, style="margin: 5px 0px 20px;"),
167
- # br(),
168
- h5("Buah/Sayur"),
169
- h4(cari_menu$buah_sayur, style="margin: 5px 0px 20px;"),
170
- # br(),
171
- h5("Lemak Tambahan"),
172
- h4(cari_menu$lemak_tambahan, style="margin: 5px 0px 20px;"),
173
- # br(),
174
- h5("Camilan"),
175
- h4(cari_menu$camilan, style="margin: 5px 0px 20px;"),
176
- # br(),
177
- h5("Gejala Alergi"),
178
- h4(cari_menu$gejala, style="margin: 5px 0px 20px;color: red;"),
179
- # br()
180
- h5("Tanggal Terjadi Gejala"),
181
- h4(ifelse(is.na(cari_menu$tgl_gejala), "-", cari_menu$tgl_gejala), style="margin: 5px 0px 20px;color: red;")#,
182
-
 
 
 
 
 
 
 
 
 
183
  )
184
  }
185
  })
186
-
187
  cari_history <- reactive({
188
  if(input$keyword != ""){
189
- menu_tbl() |>
190
  collect() |>
191
- mutate(across(karbo:gejala, ~if_else(.x == "", "-", .x))) |>
192
- mutate(tgl_gejala = tgl_gejala |> as.Date() |> format("%d %b %Y")) |>
193
  mutate(kolom := tolower(!!sym(input$komponen))) |> #slice(1)
194
- filter(str_detect(kolom, tolower(input$keyword)))
 
195
  } else {
196
  x <- data.frame(x = 0)
197
  return(x)
198
  }
199
  })
200
-
201
  history <- reactive({
202
- cari_history() |>
203
- filter(as.Date(tanggal) == input$history_date)
204
  })
205
-
206
  output$out_history <- renderUI({
207
  if(ncol(cari_history()) == 1 | input$keyword == "" | nrow(history()) == 0){
208
- wellPanel(style="background-color:transparent;",
209
  p("Tidak ada catatan", style="text-align: center;")
210
  )
211
  } else if(ncol(cari_history()) >= 1){
212
- tagList(
213
- wellPanel(style="background-color:transparent;",
214
- h5("Tanggal"),
215
- h4(format(as.Date(history()$tanggal), "%d %b %Y"), style="margin: 5px 0px 20px;"),
216
- # br(),
217
- h5("Karbohidrat"),
218
- h4(history()$karbo, style="margin: 5px 0px 20px;"),
219
- # br(),
220
- h5("Protein Hewani"),
221
- h4(history()$protein_hewani, style="margin: 5px 0px 20px;"),
222
- # br(),
223
- h5("Protein Nabati"),
224
- h4(history()$protein_nabati, style="margin: 5px 0px 20px;"),
225
- # br(),
226
- h5("Buah/Sayur"),
227
- h4(history()$buah_sayur, style="margin: 5px 0px 20px;"),
228
- # br(),
229
- h5("Lemak Tambahan"),
230
- h4(history()$lemak_tambahan, style="margin: 5px 0px 20px;"),
231
- # br(),
232
- h5("Camilan"),
233
- h4(history()$camilan, style="margin: 5px 0px 20px;"),
234
- # br(),
235
- h5("Gejala Alergi"),
236
- h4(history()$gejala, style="margin: 5px 0px 20px;color: red;"),
237
- # br()
238
- h5("Tanggal terjadi Gejala"),
239
- h4(ifelse(is.na(history()$tgl_gejala), "-", history()$tgl_gejala), style="margin: 5px 0px 20px;color: red;")#,
240
-
 
 
 
 
 
 
 
 
 
 
 
 
241
  )
242
-
243
  )
244
  }
245
  })
246
  output$out_cari_komponen <- renderUI({
247
-
248
  if(ncol(cari_history()) == 1 | input$keyword == "" | nrow(cari_history()) == 0){
249
- p("Tidak ada catatan", style="text-align: center;")
250
  } else if(nrow(cari_history()) > 1){
 
251
  tagList(
252
- div(style="display:flex;margin:auto 0px;",
253
- # column(1,
254
- actionButton("prev_history", "<", style="width:5rem;height:3.4rem;"),
255
- # ),
256
- # column(10,
257
- airDatepickerInput("history_date", NULL, width = "100%",
258
- value = min(cari_history()$tanggal)),
259
- # ),
260
- # column(1,
261
- actionButton("nex_history", ">", style="width:5rem;height:3.4rem;")
262
- # )
263
- ),
264
- uiOutput("out_history")
265
  )
266
-
267
  } else {
268
- tagList(
269
- wellPanel(style="background-color:transparent;",
270
- h5("Tanggal"),
271
- h4(format(as.Date(cari_history()$tanggal), "%d %b %Y"), style="margin: 5px 0px 20px;"),
272
- # br(),
273
- h5("Karbohidrat"),
274
- h4(cari_history()$karbo, style="margin: 5px 0px 20px;"),
275
- # br(),
276
- h5("Protein Hewani"),
277
- h4(cari_history()$protein_hewani, style="margin: 5px 0px 20px;"),
278
- # br(),
279
- h5("Protein Nabati"),
280
- h4(cari_history()$protein_nabati, style="margin: 5px 0px 20px;"),
281
- # br(),
282
- h5("Buah/Sayur"),
283
- h4(cari_history()$buah_sayur, style="margin: 5px 0px 20px;"),
284
- # br(),
285
- h5("Lemak Tambahan"),
286
- h4(cari_history()$lemak_tambahan, style="margin: 5px 0px 20px;"),
287
- # br(),
288
- h5("Camilan"),
289
- h4(cari_history()$camilan, style="margin: 5px 0px 20px;"),
290
- # br(),
291
- h5("Gejala Alergi"),
292
- h4(cari_history()$gejala, style="margin: 5px 0px 20px;color: red;"),
293
- # br()
294
- h5("Tanggal terjadi Gejala"),
295
- h4(ifelse(is.na(cari_history()$tgl_gejala), "-", cari_history()$tgl_gejala), style="margin: 5px 0px 20px;color: red;")#,
296
-
 
 
 
 
 
 
 
 
 
 
 
297
  )
298
  )
299
  }
300
-
301
  })
302
-
303
- observeEvent(input$update_edit, {
304
- shinyalert(type = "info",
305
- text = "Anda yakin ingin memperbarui data?",
306
- showCancelButton = TRUE, showConfirmButton = TRUE,
307
  callbackR = function(x){
308
  if(x != FALSE){
309
- shinyalert(type = "info", text = "Sedang diproses...", immediate = TRUE,
310
  showConfirmButton = FALSE, closeOnEsc = FALSE, closeOnClickOutside = FALSE)
311
-
312
  qr <- glue("UPDATE public.menu SET gejala = '{input$edit_gejala}', tgl_gejala = '{input$edit_tgl_gejala}' WHERE tanggal = '{input$edit_tanggal}'")
313
  r <- dbSendQuery(pg_con, qr)
314
  dbClearResult(r)
315
-
316
- updateDateInput(session, "edit_tgl_gejala", "Tanggal Terjadi Gejala", value = Sys.Date())
317
- updateTextInput(session, "edit_gejala", "Gejala Alergi", value = "")
318
- updateDateInput(session, "edit_tanggal", "Tanggal Pemberian MPASI", value = Sys.Date())
319
-
320
- shinyalert(type = "success", text = "Data berhasil diperbarui", immediate = TRUE,
321
- showConfirmButton = TRUE, closeOnEsc = FALSE, closeOnClickOutside = FALSE)
322
-
 
323
  }
324
  })
325
  })
326
  }
327
 
328
- shinyApp(ui, server, onStart = function(){
329
- source("dbconnect.R")
330
- onStop(function(){
331
- dbDisconnect(pg_con)
332
- })
333
- })
 
 
 
1
  library(shiny)
2
+ library(shinyMobile)
3
  library(shinyalert)
4
  library(shinyWidgets)
5
  library(glue)
 
7
  library(dbplyr)
8
  library(stringr)
9
 
10
+ word_wrap <- function(x){
11
+ str_split(x, ",") |>
12
+ unlist() |>
13
+ str_trim("both") |>
14
+ sapply(FUN = function(z){
15
+ if_else(nchar(z) > 90,
16
+ paste(substring(z, 1, 30), substring(z, 31, 60), substring(z, 61, 90), substring(z, 91), sep = "<br>"),
17
+ if_else(nchar(z) > 60, paste(substring(z, 1, 30), substring(z, 31, 60), substring(z, 61), sep = "<br>"),
18
+ if_else(nchar(z) > 30, paste(substring(z, 1, 30), substring(z, 31), sep = "<br>"),
19
+ z)))
20
+ }) |>
21
+ str_c(collapse = ",<br>") |>
22
+ HTML()
23
+ }
24
+
25
+ ui <- f7Page(
26
+ options = list(theme = "ios", dark = FALSE, skeletonOnLoad = TRUE),
27
+ allowPWA = TRUE,
28
+ f7TabLayout(
29
+ navbar = f7Navbar(title = "SIMPASI"),
30
+ f7Tabs(animated = T,
31
+ id = "tabs",
32
+ f7Tab(tabName = "input_menu", title = "Input Menu", active = TRUE, icon = f7Icon("book"),
33
+ # Content
34
+ f7Card(
35
+ h4(span(f7Icon("calendar"), "Tanggal"), style="margin:0px 0px 10px 0px;"),
36
+ f7DatePicker("tgl", NULL),
37
+ hr()
38
+ ),
39
+ f7Card(
40
+ h4(span(f7Icon("tray"), "Karbohidrat"), style="margin:0px 0px 10px 0px;"),
41
+ f7TextArea("karbo", NULL, resize = TRUE),
42
+ hr()
43
+ ),
44
+ f7Card(
45
+ h4(span(f7Icon("poultry_leg"), "Protein Hewani"), style="margin:0px 0px 10px 0px;"),
46
+ f7TextArea("protein_hewani", NULL, resize = TRUE),
47
+ hr()
48
+ ),
49
+ f7Card(
50
+ h4(span(f7Icon("tree"), "Protein Nabati"), style="margin:0px 0px 10px 0px;"),
51
+ f7TextArea("protein_nabati", NULL, resize = TRUE),
52
+ hr()
53
+ ),
54
+ f7Card(
55
+ h4(span(f7Icon("leaf_arrow_circlepath"), "Buah/Sayur"), style="margin:0px 0px 10px 0px;"),
56
+ f7TextArea("buah_sayur", NULL, resize = TRUE),
57
+ hr()
58
+ ),
59
+ f7Card(
60
+ h4(span(f7Icon("drop"), "Lemak Tambahan"), style="margin:0px 0px 10px 0px;"),
61
+ f7TextArea("lemak_tambahan", NULL, resize = TRUE),
62
+ hr()
63
+ ),
64
+ f7Card(
65
+ h4(span(f7Icon("circle_grid_hex"), "Camilan"), style="margin:0px 0px 10px 0px;"),
66
+ f7TextArea("camilan", NULL, resize = TRUE),
67
+ hr()
68
+ ),
69
+ f7Card(
70
+ h4(span(f7Icon("bandage"), "Gejala Alergi"), style="margin:0px 0px 10px 0px;"),
71
+ f7TextArea("gejala", NULL, resize = TRUE),
72
+ hr()
73
+ ),
74
+ f7Card(
75
+ h4(span(f7Icon("calendar_today"), "Tanggal Terjadi Gejala"), style="margin:0px 0px 10px 0px;"),
76
+ f7DatePicker("tgl_gejala", NULL),
77
+ hr()
78
+ ),
79
+
80
+ f7Card(
81
+ f7Button("save", "Simpan", size = "large"),
82
+ br(),
83
+ p("Copyright (C) 2024 aephidayatuloh", style = "text-align: center")
84
+ )
85
+ ),
86
+ f7Tab(tabName = "cari", title = "Cari Catatan", icon = f7Icon("doc_text_search"),
87
+ # Content
88
+ f7Card(
89
+ f7Select("komponen", "Cari berdasarkan:", width = "100%",
90
+ choices = list("Tanggal" = "tanggal",
91
+ "Karbohidrat" = "karbo",
92
+ "Protein Hewani" = "protein_hewani",
93
+ "Protein Nabati" = "protein_nabati",
94
+ "Buah/Sayur" = "buah_sayur",
95
+ "Lemak Tambahan" = "lemak_tambahan",
96
+ "Camilan" = "camilan",
97
+ "Gejala Alergi" = "gejala"))
98
+ ),
99
+ conditionalPanel("input.komponen == 'tanggal'",
100
+ f7Card(
101
+ h4(span(f7Icon("calendar"), "Tanggal MPASI"), style="margin:0px 0px 10px 0px;"),
102
+ f7DatePicker("cari_date", NULL, value = Sys.Date()),
103
+ hr()
104
+ ),
105
+ f7Card(
106
+ f7Segment(container = "row",
107
+ f7Button("prev", "< Prev", size = "large"),
108
+ f7Button("nex", "Next >", size = "large")
109
+ )
110
+ ),
111
+ f7Card(uiOutput("out_cari_tgl"))
112
+
113
+ ),
114
+ conditionalPanel("input.komponen != 'tanggal'",
115
+ f7Card(
116
+ p("Kata Kunci", style="text-align:center;"),
117
+ f7Text("keyword", NULL, value = ""),
118
+ hr(style="margin:5px 0px;")
119
+ ),
120
+ uiOutput("out_cari_komponen")
121
+
122
+ )
123
+
124
+
125
+ ),
126
+ f7Tab(tabName = "update_gejala", title = "Update Gejala", icon = f7Icon("bubble_left_bubble_right"),
127
+ # Content
128
+ f7Card(
129
+ h4(span(f7Icon("calendar_today"), "Tanggal Terjadi Gejala"), style="margin:0px 0px 10px 0px;"),
130
+ f7DatePicker("edit_tgl_gejala", NULL),
131
+ hr()
132
+ ),
133
+ f7Card(
134
+ h4(span(f7Icon("bandage"), "Gejala Alergi"), style="margin:0px 0px 10px 0px;"),
135
+ f7TextArea("edit_gejala", NULL, resize = TRUE),
136
+ hr()
137
+ ),
138
+ f7Card(
139
+ h4(span(f7Icon("bandage"), "Tanggal Pemberian MPASI"), style="margin:0px 0px 10px 0px;"),
140
+ f7DatePicker("edit_tanggal", NULL),
141
+ hr()
142
+ ),
143
+ f7Card(
144
+ f7Button("edit_update", "Update", size = "large")
145
+ )
146
+ )
147
  )
148
  )
149
  )
 
159
  })
160
 
161
  observeEvent(input$save, {
162
+ shinyalert(text = "Yakin ingin menyimpan?", type = "info", showCancelButton = TRUE,
163
  callbackR = function(x){
164
  if(x != FALSE){
165
  shinyalert(text = "Menyimpan data ...", type = "info", showConfirmButton = FALSE, closeOnEsc = FALSE, closeOnClickOutside = FALSE)
166
  tgl_gejala <- if_else(input$gejala %in% c(NA, NULL, "", "-"), NA , as.Date(input$tgl_gejala))
167
+
168
  # source("dbconnect.R")
169
+ # query <- glue("INSERT INTO public.menu (id_parent, id_anak, tanggal, karbo, protein_hewani, protein_nabati, buah_sayur, lemak_tambahan, camilan, gejala, tgl_gejala, created_date)
170
  # VALUES (1, 2, '{input$tgl}', '{input$karbo}', '{input$protein_hewani}', '{input$protein_nabati}', '{input$buah_sayur}', '{input$lemak_tambahan}', '{input$camilan}', '{input$gejala}', {tgl_gejala}, '{Sys.time()}')")
171
  menu_data <- tribble(
172
+ ~id_parent, ~id_anak, ~tanggal, ~karbo, ~protein_hewani, ~protein_nabati, ~buah_sayur, ~lemak_tambahan, ~camilan, ~gejala, ~tgl_gejala, ~created_date,
173
  1, 2, input$tgl, input$karbo, input$protein_hewani, input$protein_nabati, input$buah_sayur, input$lemak_tambahan, input$camilan, input$gejala, tgl_gejala, Sys.time()
174
  )
175
+
176
+ pg_con |>
177
  dbAppendTable(name = "menu", value = menu_data)
178
  # dbDisconnect(pg_con)
179
+ updateF7DatePicker(session = session, "tgl", NULL, value = Sys.Date())
180
+ updateF7TextArea(session = session, "karbo", NULL, value = "")
181
+ updateF7TextArea(session = session, "protein_hewani", NULL, value = "")
182
+ updateF7TextArea(session = session, "protein_nabati", NULL, value = "")
183
+ updateF7TextArea(session = session, "buah_sayur", NULL, value = "")
184
+ updateF7TextArea(session = session, "lemak_tambahan", NULL, value = "")
185
+ updateF7TextArea(session = session, "camilan", NULL, value = "")
186
+ updateF7TextArea(session = session, "gejala", NULL, value = "")
187
+ updateF7DatePicker(session = session, "tgl_gejala", NULL, value = Sys.Date())
188
  # closeAlert()
189
  shinyalert(text = "Data berhasil disimpan.", type = "success", immediate = TRUE)
190
+
191
  }
192
  })
193
  })
194
+
195
  observeEvent(input$prev, {
196
  date_val <- reactiveValues()
197
  date_val$curr_dt <- input$cari_date
198
+ updateF7DatePicker("cari_date", NULL, value = date_val$curr_dt - 1, session = session)
199
+ }
200
  )
201
+
202
  observeEvent(input$nex, {
203
  date_val <- reactiveValues()
204
  date_val$curr_dt <- input$cari_date
205
+ updateF7DatePicker("cari_date", NULL, value = date_val$curr_dt + 1, session = session)
206
  }
207
  )
208
+
209
  observeEvent(input$prev_history, {
210
+ date_val_history <- reactiveValues()
211
+ date_val_history$curr_dt_history <- as.Date(input$history_date)
212
+ updateF7DatePicker(inputId = "history_date", NULL, value = date_val_history$curr_dt_history - 1, session = session)
213
  }
214
  )
215
+
216
  observeEvent(input$nex_history, {
217
+ message("Next sampai sini bisa")
218
+ date_val_history <- reactiveValues()
219
+ message("Next sampai reactivevalues() bisa")
220
+ date_val_history$curr_dt_history <- as.Date(input$history_date)
221
+ message("Next sampai update reactiveValues bisa")
222
+ updateF7DatePicker(inputId = "history_date", NULL, value = date_val_history$curr_dt_history + 1, session = session)
223
  }
224
  )
225
 
226
  output$out_cari_tgl <- renderUI({
227
+ cari_menu <- menu_tbl() |>
228
  collect() |>
229
+ mutate(across(karbo:gejala, ~if_else(.x == "", "-", .x))) |>
230
+ filter(tanggal == input$cari_date) |>
231
  mutate(tgl_gejala = tgl_gejala |> as.Date() |> format("%d %b %Y"))
232
+
233
  if(nrow(cari_menu) == 0){
234
  p("Tidak ada catatan", style="text-align: center;")
235
  } else {
236
+ f7List(
237
+ f7ListItem(media = f7Icon("calendar"),
238
+ header = "Tanggal",
239
+ h5(format(input$cari_date, "%d %b %Y"), style="margin: 5px 0px;")
240
+ ),
241
+ f7ListItem(media = f7Icon("tray"),
242
+ header = "Karbohidrat",
243
+ h5(word_wrap(cari_menu$karbo), style="margin: 5px 0px;")
244
+ ),
245
+ f7ListItem(media = f7Icon("poultry_leg"),
246
+ header = "Protein Hewani",
247
+ h5(word_wrap(cari_menu$protein_hewani), style="margin: 5px 0px;")
248
+ ),
249
+ f7ListItem(media = f7Icon("tree"),
250
+ header = "Protein Nabati",
251
+ h5(word_wrap(cari_menu$protein_nabati), style="margin: 5px 0px;")
252
+ ),
253
+ f7ListItem(media = f7Icon("leaf_arrow_circlepath"),
254
+ header = "Buah/Sayur",
255
+ h5(word_wrap(cari_menu$buah_sayur), style="margin: 5px 0px;")
256
+ ),
257
+ f7ListItem(media = f7Icon("drop"),
258
+ header = "Lemak Tambahan",
259
+ h5(word_wrap(cari_menu$lemak_tambahan), style="margin: 5px 0px;")
260
+ ),
261
+ f7ListItem(media = f7Icon("circle_grid_hex"),
262
+ header = "Camilan",
263
+ h5(word_wrap(cari_menu$camilan), style="margin: 5px 0px;")
264
+ ),
265
+ f7ListItem(media = f7Icon("bandage"),
266
+ header = "Gejala Alergi",
267
+ h5(word_wrap(cari_menu$gejala), style="margin: 5px 0px;color: red;")
268
+ ),
269
+ f7ListItem(media = f7Icon("calendar_today"),
270
+ header = "Tanggal Terjadi Gejala",
271
+ h5(ifelse(is.na(cari_menu$tgl_gejala), "-", cari_menu$tgl_gejala), style="margin: 5px 0px;color: red;")
272
+ )
273
  )
274
  }
275
  })
276
+
277
  cari_history <- reactive({
278
  if(input$keyword != ""){
279
+ menu_tbl() |>
280
  collect() |>
281
+ mutate(across(karbo:gejala, ~if_else(.x == "", "-", .x))) |>
282
+ mutate(tgl_gejala = tgl_gejala |> as.Date() |> format("%d %b %Y")) |>
283
  mutate(kolom := tolower(!!sym(input$komponen))) |> #slice(1)
284
+ filter(str_detect(kolom, tolower(input$keyword))) |>
285
+ arrange(tanggal)
286
  } else {
287
  x <- data.frame(x = 0)
288
  return(x)
289
  }
290
  })
291
+
292
  history <- reactive({
293
+ cari_history() |>
294
+ slice(input$index_history_komponen)
295
  })
296
+
297
  output$out_history <- renderUI({
298
  if(ncol(cari_history()) == 1 | input$keyword == "" | nrow(history()) == 0){
299
+ wellPanel(style="background-color:transparent;",
300
  p("Tidak ada catatan", style="text-align: center;")
301
  )
302
  } else if(ncol(cari_history()) >= 1){
303
+ f7Card(
304
+ f7List(
305
+
306
+ f7ListItem(media = f7Icon("calendar"),
307
+ header = "Tanggal",
308
+ h5(format(as.Date(history()$tanggal), "%d %b %Y"), style="margin: 5px 0px;")
309
+ ),
310
+ f7ListItem(media = f7Icon("tray"),
311
+ header = "Karbohidrat",
312
+ h5(word_wrap(history()$karbo),
313
+ style="margin: 5px 0px;max-width: 300px;overflow-wrap: inherit;word-wrap: inherit;hyphens: auto;")
314
+ ),
315
+ f7ListItem(media = f7Icon("poultry_leg"),
316
+ header = "Protein Hewani",
317
+ h5(word_wrap(history()$protein_hewani),
318
+ style="margin: 5px 0px;max-width: 300px;overflow-wrap: inherit;word-wrap: inherit;hyphens: auto;")
319
+ ),
320
+ f7ListItem(media = f7Icon("tree"),
321
+ header = "Protein Nabati",
322
+ h5(word_wrap(history()$protein_nabati), style="margin: 5px 0px;max-width: 300px;")
323
+ ),
324
+ f7ListItem(media = f7Icon("leaf_arrow_circlepath"),
325
+ header = "Buah/Sayur",
326
+ h5(word_wrap(history()$buah_sayur), style="margin: 5px 0px;")
327
+ ),
328
+ f7ListItem(media = f7Icon("drop"),
329
+ header = "Lemak Tambahan",
330
+ h5(word_wrap(history()$lemak_tambahan), style="margin: 5px 0px;")
331
+ ),
332
+ f7ListItem(media = f7Icon("circle_grid_hex"),
333
+ header = "Camilan",
334
+ h5(word_wrap(history()$camilan), style="margin: 5px 0px;")
335
+ ),
336
+ f7ListItem(media = f7Icon("bandage"),
337
+ header = "Gejala Alergi",
338
+ h5(word_wrap(history()$gejala), style="margin: 5px 0px;color: red;")
339
+ ),
340
+ f7ListItem(media = f7Icon("calendar_today"),
341
+ header = "Tanggal Terjadi Gejala",
342
+ h5(ifelse(is.na(history()$tgl_gejala), "-", history()$tgl_gejala), style="margin: 5px 0px;color: red;")
343
+ )
344
  )
 
345
  )
346
  }
347
  })
348
  output$out_cari_komponen <- renderUI({
349
+
350
  if(ncol(cari_history()) == 1 | input$keyword == "" | nrow(cari_history()) == 0){
351
+ f7Card(p("Tidak ada catatan", style="text-align: center;"))
352
  } else if(nrow(cari_history()) > 1){
353
+ n_history_komponen <- nrow(cari_history())
354
  tagList(
355
+ # f7DatePicker("history_date", NULL,
356
+ # value = min(cari_history()$tanggal)),
357
+ div(style="margin-left: 120px;width:150%;",
358
+ f7Stepper("index_history_komponen", label = NULL, value = 1, min = 1, max = n_history_komponen, step = 1,
359
+ raised = TRUE, rounded = TRUE, size = "small", fill = TRUE, color = "blue", wraps = TRUE)
360
+ ),
361
+ # f7Segment(container = "segment",
362
+ # f7Button("prev_history", "< Prev"),
363
+ # f7Button("nex_history", "Next >")
364
+ # ),
365
+ uiOutput("out_history")
 
 
366
  )
367
+
368
  } else {
369
+ f7Card(
370
+ f7List(
371
+ f7ListItem(media = f7Icon("calendar"),
372
+ header = "Tanggal",
373
+ h5(format(as.Date(cari_history()$tanggal), "%d %b %Y"), style="margin: 5px 0px;")
374
+ ),
375
+ f7ListItem(media = f7Icon("tray"),
376
+ header = "Karbohidrat",
377
+ h5(word_wrap(cari_history()$karbo),
378
+ style="margin: 5px 0px;max-width: 300px;overflow-wrap: inherit;word-wrap: inherit;hyphens: auto;")
379
+ ),
380
+ f7ListItem(media = f7Icon("poultry_leg"),
381
+ header = "Protein Hewani",
382
+ h5(word_wrap(cari_history()$protein_hewani),
383
+ style="margin: 5px 0px;max-width: 300px;overflow-wrap: inherit;word-wrap: inherit;hyphens: auto;")
384
+ ),
385
+ f7ListItem(media = f7Icon("tree"),
386
+ header = "Protein Nabati",
387
+ h5(word_wrap(cari_history()$protein_nabati), style="margin: 5px 0px;max-width: 300px;")
388
+ ),
389
+ f7ListItem(media = f7Icon("leaf_arrow_circlepath"),
390
+ header = "Buah/Sayur",
391
+ h5(word_wrap(cari_history()$buah_sayur), style="margin: 5px 0px;")
392
+ ),
393
+ f7ListItem(media = f7Icon("drop"),
394
+ header = "Lemak Tambahan",
395
+ h5(word_wrap(cari_history()$lemak_tambahan), style="margin: 5px 0px;")
396
+ ),
397
+ f7ListItem(media = f7Icon("circle_grid_hex"),
398
+ header = "Camilan",
399
+ h5(word_wrap(cari_history()$camilan), style="margin: 5px 0px;")
400
+ ),
401
+ f7ListItem(media = f7Icon("bandage"),
402
+ header = "Gejala Alergi",
403
+ h5(word_wrap(cari_history()$gejala), style="margin: 5px 0px;color: red;")
404
+ ),
405
+ f7ListItem(media = f7Icon("calendar_today"),
406
+ header = "Tanggal Terjadi Gejala",
407
+ h5(ifelse(is.na(cari_history()$tgl_gejala), "-", cari_history()$tgl_gejala), style="margin: 5px 0px;color: red;")
408
+ )
409
  )
410
  )
411
  }
412
+
413
  })
414
+
415
+ observeEvent(input$edit_update, {
416
+ shinyalert(type = "info",
417
+ text = "Anda yakin ingin memperbarui data?",
418
+ showCancelButton = TRUE, showConfirmButton = TRUE,
419
  callbackR = function(x){
420
  if(x != FALSE){
421
+ shinyalert(type = "info", text = "Sedang diproses...", immediate = TRUE,
422
  showConfirmButton = FALSE, closeOnEsc = FALSE, closeOnClickOutside = FALSE)
423
+
424
  qr <- glue("UPDATE public.menu SET gejala = '{input$edit_gejala}', tgl_gejala = '{input$edit_tgl_gejala}' WHERE tanggal = '{input$edit_tanggal}'")
425
  r <- dbSendQuery(pg_con, qr)
426
  dbClearResult(r)
427
+
428
+ updateF7DatePicker("edit_tgl_gejala", NULL, value = Sys.Date(), session = session)
429
+ updateF7TextArea("edit_gejala", NULL, value = "", session = session)
430
+ updateF7DatePicker("edit_tanggal", NULL, value = Sys.Date(), session = session)
431
+
432
+ shinyalert(type = "success", text = "Data berhasil diperbarui", immediate = TRUE,
433
+ showCancelButton = FALSE, showConfirmButton = TRUE,
434
+ closeOnEsc = FALSE, closeOnClickOutside = FALSE)
435
+
436
  }
437
  })
438
  })
439
  }
440
 
441
+ shinyApp(ui, server,
442
+ onStart = function(){
443
+ source("dbconnect.R")
444
+ onStop(function(){
445
+ dbDisconnect(pg_con)
446
+ })
447
+ }
448
+ )