Skip to content

Commit

Permalink
feat: add mod_add.R
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepanshKhurana committed Jun 23, 2024
1 parent 733694d commit 41f45ee
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ box::use(

box::use(
app/view/mod_add_selector,
app/view/mod_add,
app/view/mod_view,
app/view/mod_view_selector,
app/view/mod_edit,
Expand Down Expand Up @@ -39,7 +40,8 @@ server <- function(id) {
table_name = NULL,
row = NULL,
operation = NULL,
table_data = NULL
table_data = NULL,
user_input = NULL
)

shiny$observeEvent(
Expand Down Expand Up @@ -71,7 +73,9 @@ server <- function(id) {
)
}
})
}, ignoreNULL = TRUE, ignoreInit = TRUE
},
ignoreNULL = TRUE,
ignoreInit = TRUE
)

shiny$observeEvent(input$app_mode,
Expand All @@ -97,6 +101,18 @@ server <- function(id) {
mod_add_selector$ui(
ns("selector")
)

})

output$data_area_ui <- shiny$renderUI({
mod_add$server(
"data_area",
selected
)

mod_add$ui(
ns("data_area")
)
})
}
},
Expand Down
93 changes: 93 additions & 0 deletions app/view/mod_add.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
box::use(
glue[
glue
],
shiny,
stats[
setNames
],
tools[
toTitleCase
],
)

#' @export
ui <- function(id) {
ns <- shiny$NS(id)
shiny$div(
class = "argus-data-area",
shiny$uiOutput(ns("argus_data"))
)
}

#' @export
server <- function(id, selected) {
shiny$moduleServer(id, function(input, output, session) {

ns <- session$ns

empty_dataframe <- shiny$reactive({
data.frame(
selected$table_data()[0, ]
)
})

max_id <- shiny$reactive({
selected$table_data()$id |>
unlist() |>
max()
})

shiny$observeEvent(selected$table_data, {

output$argus_data <- shiny$renderUI({

keys <- names(empty_dataframe())
labels <- gsub(
"_",
" ",
names(empty_dataframe())
) |>
toTitleCase()

keys <- setNames(as.list(labels), keys)
total <- length(keys)

shiny$div(
class = "argus-data-grid",
lapply(
names(keys),
function(key) {
if (key == "id") {
class <- "argus-field-block is-id-block"
element <- shiny$p(
class = "argus-field-value",
max_id() + 1
)
} else {
class <- "argus-field-block"
element <- shiny$textInput(
inputId = ns(key),
label = NULL,
value = ""
) |>
shiny$tagAppendAttributes(
class = "argus-field-input"
)
}
shiny$div(
class = class,
shiny$p(
class = "argus-field-heading",
keys[key]
),
element
)
}
)
)
})
}, ignoreNULL = TRUE)

})
}

0 comments on commit 41f45ee

Please sign in to comment.