aephidayatuloh
commited on
Commit
·
aafec2f
1
Parent(s):
fc8ce0a
change to mobile-friendly only using shinyMobile Framework7
Browse files
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 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
| 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 |
-
|
| 121 |
-
|
| 122 |
)
|
| 123 |
-
|
| 124 |
observeEvent(input$nex, {
|
| 125 |
date_val <- reactiveValues()
|
| 126 |
date_val$curr_dt <- input$cari_date
|
| 127 |
-
|
| 128 |
}
|
| 129 |
)
|
| 130 |
-
|
| 131 |
observeEvent(input$prev_history, {
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
}
|
| 136 |
)
|
| 137 |
-
|
| 138 |
observeEvent(input$nex_history, {
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 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 |
-
|
| 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 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 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 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
),
|
| 264 |
-
uiOutput("out_history")
|
| 265 |
)
|
| 266 |
-
|
| 267 |
} else {
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
)
|
| 298 |
)
|
| 299 |
}
|
| 300 |
-
|
| 301 |
})
|
| 302 |
-
|
| 303 |
-
observeEvent(input$
|
| 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 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
shinyalert(type = "success", text = "Data berhasil diperbarui", immediate = TRUE,
|
| 321 |
-
|
| 322 |
-
|
|
|
|
| 323 |
}
|
| 324 |
})
|
| 325 |
})
|
| 326 |
}
|
| 327 |
|
| 328 |
-
shinyApp(ui, server,
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 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 |
+
)
|