aephidayatuloh
commited on
Commit
·
76126cd
1
Parent(s):
f6caafb
R app file upload
Browse files- app.R +43 -0
- dbconnect.R +11 -0
- simpasi.Rproj +15 -0
app.R
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
library(shiny)
|
| 2 |
+
library(shinyalert)
|
| 3 |
+
library(shinyWidgets)
|
| 4 |
+
library(glue)
|
| 5 |
+
|
| 6 |
+
ui <- fluidPage(
|
| 7 |
+
h2("SIMPASI"),
|
| 8 |
+
br(),
|
| 9 |
+
# selectInput("anak", "Anak", choices = c("Ara", "Ibrahim")),
|
| 10 |
+
dateInput("tgl", "Tanggal"),
|
| 11 |
+
textInput("karbo", "Karbohidrat"),
|
| 12 |
+
textInput("protein_hewani", "Protein Hewani"),
|
| 13 |
+
textInput("protein_nabati", "Protein Nabati"),
|
| 14 |
+
textInput("buah_sayur", "Buah/Sayur"),
|
| 15 |
+
textInput("lemak_tambahan", "Lemak Tambahan"),
|
| 16 |
+
textAreaInput("camilan", "Camilan"),
|
| 17 |
+
textAreaInput("gejala", "Gejala Alergi"),
|
| 18 |
+
actionBttn("save", "Simpan"),
|
| 19 |
+
br()
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
server <- function(input, output, session){
|
| 23 |
+
observeEvent(input$save, {
|
| 24 |
+
shinyalert(text = "Yakin ingin menyimpan?", type = "info", showCancelButton = TRUE,
|
| 25 |
+
callbackR = function(x){
|
| 26 |
+
if(x != FALSE){
|
| 27 |
+
shinyalert(text = "Menyimpan data ...", type = "info", showConfirmButton = FALSE, closeOnEsc = FALSE, closeOnClickOutside = FALSE)
|
| 28 |
+
source("dbconnect.R")
|
| 29 |
+
query <- glue("INSERT INTO public.menu (id_parent, id_anak, tanggal, karbo, protein_hewani, protein_nabati, buah_sayur, lemak_tambahan, camilan, gejala, created_date)
|
| 30 |
+
VALUES (1, 2, '{input$tgl}', '{input$karbo}', '{input$protein_hewani}', '{input$protein_nabati}', '{input$buah_sayur}', '{input$lemak_tambahan}', '{input$camilan}', '{input$gejala}', '{Sys.time()}')")
|
| 31 |
+
query <- pg_con |>
|
| 32 |
+
dbSendQuery(query)
|
| 33 |
+
dbClearResult(query)
|
| 34 |
+
dbDisconnect(pg_con)
|
| 35 |
+
# closeAlert()
|
| 36 |
+
shinyalert(text = "Data berhasil disimpan.", type = "success", immediate = TRUE)
|
| 37 |
+
|
| 38 |
+
}
|
| 39 |
+
})
|
| 40 |
+
})
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
shinyApp(ui, server)
|
dbconnect.R
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
library(RPostgres)
|
| 2 |
+
|
| 3 |
+
pg_con <- dbConnect(Postgres(),
|
| 4 |
+
host = "batyr.db.elephantsql.com",
|
| 5 |
+
port = 5432,
|
| 6 |
+
dbname = "zpcpmrwo",
|
| 7 |
+
user = "zpcpmrwo",
|
| 8 |
+
password = "Ui66Mhs3jUh4jsQjRYnKyUke_aJ1r9Mq")
|
| 9 |
+
|
| 10 |
+
# dbListTables(pg_con)
|
| 11 |
+
# dbDisconnect(pg_con)
|
simpasi.Rproj
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Version: 1.0
|
| 2 |
+
|
| 3 |
+
RestoreWorkspace: Default
|
| 4 |
+
SaveWorkspace: Default
|
| 5 |
+
AlwaysSaveHistory: Default
|
| 6 |
+
|
| 7 |
+
EnableCodeIndexing: Yes
|
| 8 |
+
UseSpacesForTab: Yes
|
| 9 |
+
NumSpacesForTab: 2
|
| 10 |
+
Encoding: UTF-8
|
| 11 |
+
|
| 12 |
+
RnwWeave: Sweave
|
| 13 |
+
LaTeX: pdfLaTeX
|
| 14 |
+
|
| 15 |
+
AutoAppendNewline: Yes
|