@@ -3,6 +3,10 @@ sidebarUI <- function(id) {
3
3
ns <- NS(id )
4
4
5
5
tagList(
6
+ useShinyjs(),
7
+ radioButtons(ns(' select' ), ' Select Option:' ,
8
+ choices = list (" Add a new cake entry" = 1 , " Modify an entry" = 2 , " Delete an entry" = 3 ),
9
+ selected = 1 ),
6
10
dateInput(ns(' date' ), ' Select Date:' , value = Sys.Date()),
7
11
timeInput(ns(" hour" ), " Time:" , value = strptime(" 12:00:00" , " %T" ), minute.steps = 10 ),
8
12
selectInput(
@@ -54,6 +58,7 @@ sidebarUI <- function(id) {
54
58
" Virologi, immunologi og parasittologi"
55
59
)),
56
60
textInput(ns(' person' ), ' Person Name:' ),
61
+ textInput(ns(' sec_in' ), ' Secret Ingredient:' ),
57
62
textAreaInput(ns(' cake_desc' ), ' Cake Description:' , rows = 3 ),
58
63
actionButton(ns(' submit' ), ' Submit' )
59
64
)
@@ -64,14 +69,30 @@ sidebarServer <- function(id, board) {
64
69
moduleServer(id , function (input , output , session ) {
65
70
ns <- session $ ns
66
71
72
+ observeEvent(input $ select , {
73
+ if (input $ select == 3 ) {
74
+ shinyjs :: hide(" hour" )
75
+ shinyjs :: hide(" room" )
76
+ shinyjs :: hide(" section" )
77
+ shinyjs :: hide(" cake_desc" )
78
+ } else {
79
+ shinyjs :: show(" hour" )
80
+ shinyjs :: show(" room" )
81
+ shinyjs :: show(" section" )
82
+ shinyjs :: show(" cake_desc" )
83
+ }
84
+ })
85
+
67
86
input_data <- reactive({
68
87
data.frame (
88
+
69
89
`Date` = input $ date ,
70
- `Hour` = input $ hour ,
90
+ `Hour` = (strftime( input $ hour , " %R " )) ,
71
91
`Room` = input $ room ,
72
92
`Section` = input $ section ,
73
- `Person Name` = input $ person ,
74
- `Cake Description` = input $ cake_desc ,
93
+ `Person.Name` = input $ person ,
94
+ `Secret.Ingredient` = input $ sec_in ,
95
+ `Cake.Description` = input $ cake_desc ,
75
96
stringsAsFactors = FALSE
76
97
)
77
98
})
@@ -83,11 +104,37 @@ sidebarServer <- function(id, board) {
83
104
input $ room ,
84
105
input $ section ,
85
106
input $ person ,
86
- input $ cake_desc
107
+ input $ sec_in
87
108
)
88
- pinned_cakes <- pin_read(board , name = paste0(' cake_user_inputs' ))
109
+ pinned_cakes <- pin_read(board ,
110
+ name = paste0(Sys.getenv(" USER_NAME" ), ' /cake_user_inputs' ))
111
+
112
+ pinned_cakes_exists <- pinned_cakes | >
113
+ dplyr :: filter(Secret.Ingredient == input $ sec_in & Person.Name == input $ person & Date == input $ date )
89
114
90
- updated_cakes <- rbind(pinned_cakes , input_data())
115
+ if (input $ select == 2 ) {
116
+ if (nrow(pinned_cakes_exists ) == 0 ) {
117
+ updated_cakes <- pinned_cakes
118
+ } else {
119
+ pinned_cakes <- pinned_cakes | >
120
+ dplyr :: filter(Secret.Ingredient != input $ sec_in | Person.Name != input $ person | Date != input $ date )
121
+ updated_cakes <- rbind(pinned_cakes , input_data())
122
+ }
123
+ } else if (input $ select == 3 ) {
124
+ if (nrow(pinned_cakes_exists ) == 0 ) {
125
+ updated_cakes <- pinned_cakes
126
+ } else {
127
+ pinned_cakes <- pinned_cakes | >
128
+ dplyr :: filter(Secret.Ingredient != input $ sec_in | Person.Name != input $ person | Date != input $ date )
129
+ updated_cakes <- pinned_cakes
130
+ }
131
+ } else {
132
+ if (nrow(pinned_cakes_exists ) != 0 ) {
133
+ updated_cakes <- pinned_cakes
134
+ } else {
135
+ updated_cakes <- rbind(pinned_cakes , input_data())
136
+ }
137
+ }
91
138
92
139
# Save the input data frame to the pin board
93
140
pin_write(
@@ -98,11 +145,13 @@ sidebarServer <- function(id, board) {
98
145
)
99
146
100
147
# Clear the inputs after submission
148
+ updateRadioButtons(session , " select" , selected = 1 )
101
149
updateDateInput(session , " date" , value = Sys.Date())
102
150
updateTimeInput(session , " hour" , value = strptime(" 12:00:00" , " %T" ))
103
151
updateSelectInput(session , " room" , selected = NULL )
104
152
updateSelectInput(session , " section" , selected = NULL )
105
153
updateTextInput(session , " person" , value = " " )
154
+ updateTextInput(session , " sec_in" , value = " " )
106
155
updateTextAreaInput(session , " cake_desc" , value = " " )
107
156
})
108
157
0 commit comments