Skip to content

Commit 556fdbe

Browse files
committed
simplify ui.R by merging outputs into a single HTML div at the server
1 parent ec49a5c commit 556fdbe

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

apps/countdown/server.R

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ server <- function(input, output, session) {
1010
schedule = as.POSIXct('2023-04-24 11:30:00')
1111
)
1212

13-
output$title <- renderText(settings$title)
14-
output$subtitle <- renderText(settings$subtitle)
15-
output$countdown <- renderText({
16-
## need to reset the cached/reactive value so that it gets updated from time to time,
17-
## as there's no external dependency triggering changes here (e.g. an input change)
18-
## that would automatically update this object to reactive
13+
output$countdown <- renderUI({
1914
invalidateLater(250)
2015
color <- ifelse(settings$schedule > Sys.time(), 'black', 'red')
21-
as.character(span(
16+
remaining <- span(
2217
round(as.period(abs(settings$schedule - Sys.time()))),
23-
style = paste('color', color, sep = ':')))
24-
})
25-
output$start <- renderText({
26-
paste('at', settings$schedule, Sys.timezone())
18+
style = paste('color', color, sep = ':'))
19+
div(
20+
h1(settings$title),
21+
h2(settings$subtitle),
22+
h3('starts in'),
23+
h1(tags$b(remaining)),
24+
h4(paste('at', settings$schedule, Sys.timezone())),
25+
class = 'center')
2726
})
2827

2928
observeEvent(input$settings_show, {

apps/countdown/ui.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ ui <- basicPage(
1010
particles(),
1111
actionBttn('settings_show', 'Settings', icon = icon('gear'), style = 'material-circle'),
1212

13-
div(
14-
h1(uiOutput('title')),
15-
h2(uiOutput('subtitle')),
16-
h3('starts in'),
17-
h1(uiOutput('countdown')),
18-
h4(uiOutput('start')),
19-
class = 'center')
13+
uiOutput('countdown')
2014

2115
)

0 commit comments

Comments
 (0)