aephidayatuloh commited on
Commit ·
26e06c3
1
Parent(s): 51b612f
update fitur
Browse files
app.R
CHANGED
|
@@ -6,7 +6,7 @@ library(dplyr)
|
|
| 6 |
library(dbplyr)
|
| 7 |
library(stringr)
|
| 8 |
|
| 9 |
-
|
| 10 |
# menu <- pg_con |>
|
| 11 |
# dbReadTable("menu") |>
|
| 12 |
# mutate(across(karbo:gejala, ~if_else(.x == "", "-", .x)))
|
|
@@ -17,6 +17,7 @@ ui <- fluidPage(
|
|
| 17 |
# br(),
|
| 18 |
tabsetPanel(
|
| 19 |
tabPanel("Input Menu MPASI",
|
|
|
|
| 20 |
# selectInput("anak", "Anak", choices = c("Ara", "Ibrahim")),
|
| 21 |
dateInput("tgl", "Tanggal"),
|
| 22 |
textInput("karbo", "Karbohidrat"),
|
|
@@ -59,18 +60,24 @@ ui <- fluidPage(
|
|
| 59 |
# )
|
| 60 |
)
|
| 61 |
),
|
| 62 |
-
tabPanel("Edit Gejala"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
)
|
| 64 |
)
|
| 65 |
|
| 66 |
server <- function(input, output, session){
|
| 67 |
menu_tbl <- reactive({
|
| 68 |
-
source("dbconnect.R")
|
| 69 |
-
menu <- pg_con |>
|
|
|
|
| 70 |
tbl("menu") |>
|
| 71 |
mutate(across(karbo:gejala, ~if_else(.x == "", "-", .x)))
|
| 72 |
-
dbDisconnect(pg_con)
|
| 73 |
-
return(menu)
|
| 74 |
})
|
| 75 |
|
| 76 |
observeEvent(input$save, {
|
|
@@ -78,15 +85,19 @@ server <- function(input, output, session){
|
|
| 78 |
callbackR = function(x){
|
| 79 |
if(x != FALSE){
|
| 80 |
shinyalert(text = "Menyimpan data ...", type = "info", showConfirmButton = FALSE, closeOnEsc = FALSE, closeOnClickOutside = FALSE)
|
| 81 |
-
tgl_gejala <- ifelse(input$gejala %in% c(NA, NULL, "", "-"), NA, input$tgl_gejala)
|
| 82 |
|
| 83 |
-
source("dbconnect.R")
|
| 84 |
-
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)
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
updateTextInput(session, "karbo", "Karbohidrat", value = "")
|
| 91 |
updateTextInput(session, "protein_hewani", "Protein Hewani", value = "")
|
| 92 |
updateTextInput(session, "protein_nabati", "Protein Nabati", value = "")
|
|
@@ -132,11 +143,12 @@ server <- function(input, output, session){
|
|
| 132 |
|
| 133 |
output$out_cari_tgl <- renderUI({
|
| 134 |
cari_menu <- menu_tbl() |>
|
| 135 |
-
|
| 136 |
-
|
|
|
|
| 137 |
|
| 138 |
if(nrow(cari_menu) == 0){
|
| 139 |
-
p("Tidak ada
|
| 140 |
} else {
|
| 141 |
tagList(
|
| 142 |
h5("Tanggal"),
|
|
@@ -164,7 +176,7 @@ server <- function(input, output, session){
|
|
| 164 |
h4(cari_menu$gejala, style="margin: 5px 0px 20px;color: red;"),
|
| 165 |
# br()
|
| 166 |
h5("Tanggal Terjadi Gejala"),
|
| 167 |
-
h4(cari_menu$tgl_gejala, style="margin: 5px 0px 20px;color: red;")#,
|
| 168 |
|
| 169 |
)
|
| 170 |
}
|
|
@@ -173,9 +185,10 @@ server <- function(input, output, session){
|
|
| 173 |
cari_history <- reactive({
|
| 174 |
if(input$keyword != ""){
|
| 175 |
menu_tbl() |>
|
|
|
|
|
|
|
| 176 |
mutate(kolom := tolower(!!sym(input$komponen))) |> #slice(1)
|
| 177 |
-
filter(str_detect(kolom, tolower(input$keyword)))
|
| 178 |
-
collect()
|
| 179 |
} else {
|
| 180 |
x <- data.frame(x = 0)
|
| 181 |
return(x)
|
|
@@ -190,7 +203,7 @@ server <- function(input, output, session){
|
|
| 190 |
output$out_history <- renderUI({
|
| 191 |
if(ncol(cari_history()) == 1 | input$keyword == "" | nrow(history()) == 0){
|
| 192 |
wellPanel(style="background-color:transparent;",
|
| 193 |
-
p("Tidak ada
|
| 194 |
)
|
| 195 |
} else if(ncol(cari_history()) >= 1){
|
| 196 |
tagList(
|
|
@@ -220,7 +233,7 @@ server <- function(input, output, session){
|
|
| 220 |
h4(history()$gejala, style="margin: 5px 0px 20px;color: red;"),
|
| 221 |
# br()
|
| 222 |
h5("Tanggal terjadi Gejala"),
|
| 223 |
-
h4(history()$tgl_gejala, style="margin: 5px 0px 20px;color: red;")#,
|
| 224 |
|
| 225 |
)
|
| 226 |
|
|
@@ -230,7 +243,7 @@ server <- function(input, output, session){
|
|
| 230 |
output$out_cari_komponen <- renderUI({
|
| 231 |
|
| 232 |
if(ncol(cari_history()) == 1 | input$keyword == "" | nrow(cari_history()) == 0){
|
| 233 |
-
p("Tidak ada
|
| 234 |
} else if(nrow(cari_history()) > 1){
|
| 235 |
tagList(
|
| 236 |
div(style="display:flex;margin:auto 0px;",
|
|
@@ -276,13 +289,36 @@ server <- function(input, output, session){
|
|
| 276 |
h4(cari_history()$gejala, style="margin: 5px 0px 20px;color: red;"),
|
| 277 |
# br()
|
| 278 |
h5("Tanggal terjadi Gejala"),
|
| 279 |
-
h4(cari_history()$tgl_gejala, style="margin: 5px 0px 20px;color: red;")#,
|
| 280 |
|
| 281 |
)
|
| 282 |
)
|
| 283 |
}
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
})
|
| 287 |
}
|
| 288 |
|
|
|
|
| 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)))
|
|
|
|
| 17 |
# br(),
|
| 18 |
tabsetPanel(
|
| 19 |
tabPanel("Input Menu MPASI",
|
| 20 |
+
br(),
|
| 21 |
# selectInput("anak", "Anak", choices = c("Ara", "Ibrahim")),
|
| 22 |
dateInput("tgl", "Tanggal"),
|
| 23 |
textInput("karbo", "Karbohidrat"),
|
|
|
|
| 60 |
# )
|
| 61 |
)
|
| 62 |
),
|
| 63 |
+
tabPanel("Edit Gejala",
|
| 64 |
+
br(),
|
| 65 |
+
dateInput("edit_tgl_gejala", "Tanggal Terjadi Gejala"),
|
| 66 |
+
textInput("edit_gejala", "Gejala Alergi"),
|
| 67 |
+
dateInput("edit_tanggal", "Tanggal Pemberian MPASI"),
|
| 68 |
+
actionButton("update_edit", "Update", icon = icon("paper-plane")))
|
| 69 |
)
|
| 70 |
)
|
| 71 |
|
| 72 |
server <- function(input, output, session){
|
| 73 |
menu_tbl <- reactive({
|
| 74 |
+
# source("dbconnect.R")
|
| 75 |
+
# menu <- pg_con |>
|
| 76 |
+
pg_con |>
|
| 77 |
tbl("menu") |>
|
| 78 |
mutate(across(karbo:gejala, ~if_else(.x == "", "-", .x)))
|
| 79 |
+
# dbDisconnect(pg_con)
|
| 80 |
+
# return(menu)
|
| 81 |
})
|
| 82 |
|
| 83 |
observeEvent(input$save, {
|
|
|
|
| 85 |
callbackR = function(x){
|
| 86 |
if(x != FALSE){
|
| 87 |
shinyalert(text = "Menyimpan data ...", type = "info", showConfirmButton = FALSE, closeOnEsc = FALSE, closeOnClickOutside = FALSE)
|
| 88 |
+
tgl_gejala <- ifelse(input$gejala %in% c(NA, NULL, "", "-"), NA , input$tgl_gejala)
|
| 89 |
|
| 90 |
+
# source("dbconnect.R")
|
| 91 |
+
# 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)
|
| 92 |
+
# 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()}')")
|
| 93 |
+
menu_data <- tribble(
|
| 94 |
+
~id_parent, ~id_anak, ~tanggal, ~karbo, ~protein_hewani, ~protein_nabati, ~buah_sayur, ~lemak_tambahan, ~camilan, ~gejala, ~tgl_gejala, ~created_date,
|
| 95 |
+
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()
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
pg_con |>
|
| 99 |
+
dbAppendTable(name = "menu", value = menu_data)
|
| 100 |
+
# dbDisconnect(pg_con)
|
| 101 |
updateTextInput(session, "karbo", "Karbohidrat", value = "")
|
| 102 |
updateTextInput(session, "protein_hewani", "Protein Hewani", value = "")
|
| 103 |
updateTextInput(session, "protein_nabati", "Protein Nabati", value = "")
|
|
|
|
| 143 |
|
| 144 |
output$out_cari_tgl <- renderUI({
|
| 145 |
cari_menu <- menu_tbl() |>
|
| 146 |
+
collect() |>
|
| 147 |
+
filter(tanggal == input$cari_date) |>
|
| 148 |
+
mutate(tgl_gejala = tgl_gejala |> as.Date() |> format("%d %b %Y"))
|
| 149 |
|
| 150 |
if(nrow(cari_menu) == 0){
|
| 151 |
+
p("Tidak ada catatan", style="text-align: center;")
|
| 152 |
} else {
|
| 153 |
tagList(
|
| 154 |
h5("Tanggal"),
|
|
|
|
| 176 |
h4(cari_menu$gejala, style="margin: 5px 0px 20px;color: red;"),
|
| 177 |
# br()
|
| 178 |
h5("Tanggal Terjadi Gejala"),
|
| 179 |
+
h4(ifelse(is.na(cari_menu$tgl_gejala), "-", cari_menu$tgl_gejala), style="margin: 5px 0px 20px;color: red;")#,
|
| 180 |
|
| 181 |
)
|
| 182 |
}
|
|
|
|
| 185 |
cari_history <- reactive({
|
| 186 |
if(input$keyword != ""){
|
| 187 |
menu_tbl() |>
|
| 188 |
+
collect() |>
|
| 189 |
+
mutate(tgl_gejala = tgl_gejala |> as.Date() |> format("%d %b %Y")) |>
|
| 190 |
mutate(kolom := tolower(!!sym(input$komponen))) |> #slice(1)
|
| 191 |
+
filter(str_detect(kolom, tolower(input$keyword)))
|
|
|
|
| 192 |
} else {
|
| 193 |
x <- data.frame(x = 0)
|
| 194 |
return(x)
|
|
|
|
| 203 |
output$out_history <- renderUI({
|
| 204 |
if(ncol(cari_history()) == 1 | input$keyword == "" | nrow(history()) == 0){
|
| 205 |
wellPanel(style="background-color:transparent;",
|
| 206 |
+
p("Tidak ada catatan", style="text-align: center;")
|
| 207 |
)
|
| 208 |
} else if(ncol(cari_history()) >= 1){
|
| 209 |
tagList(
|
|
|
|
| 233 |
h4(history()$gejala, style="margin: 5px 0px 20px;color: red;"),
|
| 234 |
# br()
|
| 235 |
h5("Tanggal terjadi Gejala"),
|
| 236 |
+
h4(ifelse(is.na(history()$tgl_gejala), "-", history()$tgl_gejala), style="margin: 5px 0px 20px;color: red;")#,
|
| 237 |
|
| 238 |
)
|
| 239 |
|
|
|
|
| 243 |
output$out_cari_komponen <- renderUI({
|
| 244 |
|
| 245 |
if(ncol(cari_history()) == 1 | input$keyword == "" | nrow(cari_history()) == 0){
|
| 246 |
+
p("Tidak ada catatan", style="text-align: center;")
|
| 247 |
} else if(nrow(cari_history()) > 1){
|
| 248 |
tagList(
|
| 249 |
div(style="display:flex;margin:auto 0px;",
|
|
|
|
| 289 |
h4(cari_history()$gejala, style="margin: 5px 0px 20px;color: red;"),
|
| 290 |
# br()
|
| 291 |
h5("Tanggal terjadi Gejala"),
|
| 292 |
+
h4(ifelse(is.na(cari_history()$tgl_gejala), "-", cari_history()$tgl_gejala), style="margin: 5px 0px 20px;color: red;")#,
|
| 293 |
|
| 294 |
)
|
| 295 |
)
|
| 296 |
}
|
| 297 |
+
|
| 298 |
+
})
|
| 299 |
+
|
| 300 |
+
observeEvent(input$update_edit, {
|
| 301 |
+
shinyalert(type = "info",
|
| 302 |
+
text = "Anda yakin ingin memperbarui data?",
|
| 303 |
+
showCancelButton = TRUE, showConfirmButton = TRUE,
|
| 304 |
+
callbackR = function(x){
|
| 305 |
+
if(x != FALSE){
|
| 306 |
+
shinyalert(type = "info", text = "Sedang diproses...", immediate = TRUE,
|
| 307 |
+
showConfirmButton = FALSE, closeOnEsc = FALSE, closeOnClickOutside = FALSE)
|
| 308 |
+
|
| 309 |
+
qr <- glue("UPDATE public.menu SET gejala = '{input$edit_gejala}', tgl_gejala = '{input$edit_tgl_gejala}' WHERE tanggal = '{input$edit_tanggal}'")
|
| 310 |
+
r <- dbSendQuery(pg_con, qr)
|
| 311 |
+
dbClearResult(r)
|
| 312 |
+
|
| 313 |
+
updateDateInput(session, "edit_tgl_gejala", "Tanggal Terjadi Gejala", value = Sys.Date())
|
| 314 |
+
updateTextInput(session, "edit_gejala", "Gejala Alergi", value = "")
|
| 315 |
+
updateDateInput(session, "edit_tanggal", "Tanggal Pemberian MPASI", value = Sys.Date())
|
| 316 |
+
|
| 317 |
+
shinyalert(type = "success", text = "Data berhasil diperbarui", immediate = TRUE,
|
| 318 |
+
showConfirmButton = TRUE, closeOnEsc = FALSE, closeOnClickOutside = FALSE)
|
| 319 |
+
|
| 320 |
+
}
|
| 321 |
+
})
|
| 322 |
})
|
| 323 |
}
|
| 324 |
|