Skip to content

Commit

Permalink
Merge pull request #39 from NorwegianVeterinaryInstitute/trish-patch-4
Browse files Browse the repository at this point in the history
Remove redundant modules
  • Loading branch information
trishangu authored Oct 3, 2024
2 parents 657ee86 + 544bfb3 commit 6f3f2de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 94 deletions.
12 changes: 8 additions & 4 deletions app.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ server <- function(input, output, session) {

# Call the modules
input_data_more <- sidebarServer('sidebar1', board) # Call sidebar module server
# Call the mail panel card module server
# Call the main panel card module server
# This module will take the second element of input_data_more as an argument
mainPanelServer_card('text1', input_data_more[[2]])
mainPanelServer('mainpanel1', board) # Call main panel module server
mainPanelServer_today('mainpanel2', board) # Call main panel module server
mainPanelServer_up('mainpanel3', board) # Call main panel module server
# Read the pin reactively
pinned_cakes <- pin_reactive_read(board,
name = paste0(Sys.getenv("USER_NAME"), '/cake_user_inputs'),
interval = 1000)
mainPanelServer('mainpanel1', pinned_cakes, "All") # Call main panel module server
mainPanelServer('mainpanel2', pinned_cakes, "today") # Call main panel module server
mainPanelServer('mainpanel3', pinned_cakes, "upcoming") # Call main panel module server
}

# Run the application
Expand Down
100 changes: 10 additions & 90 deletions mod_mainPanel.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ mainPanelServer_card <- function(id, problem) {

# Main Panel Server Module
# This module will display the Historic table
mainPanelServer <- function(id, board) {
mainPanelServer <- function(id, pinned_cakes, when) {
moduleServer(id, function(input, output, session) {

output$dataTable <- renderDT({
# Read the pinned data frame from the pin board
pinned_cakes <-
pin_reactive_read(
board,
name = paste0(Sys.getenv("USER_NAME"), '/cake_user_inputs'),
interval = 1000
)
# Hide secret ingredient
pinned_cakes <- pinned_cakes()[,c(1:5,7)]
if (when == "today") {
pinned_cakes <- pinned_cakes |>
filter(Date == Sys.Date())
}
if (when == "upcoming") {
pinned_cakes <- pinned_cakes |>
filter(Date > Sys.Date())
}
datatable(
pinned_cakes,
# Do not show row names
Expand All @@ -52,88 +54,6 @@ mainPanelServer <- function(id, board) {
"Person Name",
"Cake Description"
),
options = list(
# order table by date and then time
order = list(list(0, 'asc'), list(1, 'asc')),
columnDefs = list(
list(targets = '_all', className = 'dt-center')
))
)
})
})
}

# This module will display the upcoming table
mainPanelServer_up <- function(id, board) {
moduleServer(id, function(input, output, session) {
output$dataTable <- renderDT({
# Read the pinned data frame from the pin board
pinned_cakes <-
pin_reactive_read(
board,
name = paste0(Sys.getenv("USER_NAME"), '/cake_user_inputs'),
interval = 1000
)
# Hide secret ingredient
pinned_cakes <- pinned_cakes()[,c(1:5,7)]
# Filter all the entries that are occurring after today
pinned_cakes_up <- pinned_cakes |>
dplyr::filter(Date > Sys.Date())
datatable(
pinned_cakes_up,
# Do not show row names
rownames = FALSE,
# Add filters for each column
filter = "top",
colnames = c(
"Date",
"Hour",
"Room",
"Section",
"Person Name",
"Cake Description"
),
options = list(
# order table by date and then time
order = list(list(0, 'asc'), list(1, 'asc')),
columnDefs = list(
list(targets = '_all', className = 'dt-center')
))
)
})
})
}

# This module will display the today table
mainPanelServer_today <- function(id, board) {
moduleServer(id, function(input, output, session) {
output$dataTable <- renderDT({
# Read the pinned data frame from the pin board
pinned_cakes <-
pin_reactive_read(
board,
name = paste0(Sys.getenv("USER_NAME"), '/cake_user_inputs'),
interval = 1000
)
# Hide secret ingredient
pinned_cakes <- pinned_cakes()[,c(1:5,7)]
# Filter all the entries that are occurring today
pinned_cakes_today <- pinned_cakes |>
dplyr::filter(Date == Sys.Date())
datatable(
pinned_cakes_today,
# Do not show row names
rownames = FALSE,
# Add filters for each column
filter = "top",
colnames = c(
"Date",
"Hour",
"Room",
"Section",
"Person Name",
"Cake Description"
),
options = list(
# order table by date and then time
order = list(list(0, 'asc'), list(1, 'asc')),
Expand Down

0 comments on commit 6f3f2de

Please sign in to comment.