Skip to content

Commit e4580c8

Browse files
authored
185: Put shinyjster code in a dynamic UI to slow it down just a bit (#148)
1 parent 9d4ce82 commit e4580c8

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

inst/apps/185-report-theme/index.Rmd

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,34 +133,42 @@ output$status <- renderUI({
133133
```
134134

135135
```{r}
136-
shinyjster::shinyjster_js(
137-
"
138-
var jst = jster();
139-
jst.add(Jster.shiny.waitUntilStable);
140-
jst.add(function(done) {
141-
var wait = function() {
142-
var txt = $('#status').get(0).textContent;
143-
if (
144-
typeof txt == 'string' &&
145-
txt.length > 0 &&
146-
(txt.match(new RegExp('Pass|Fail')) ?? '').length > 0
147-
) {
148-
done();
149-
return;
136+
## `{shinyjster}` note:
137+
# From https://github.com/rstudio/shiny/issues/3780, we must delay the underlying initial
138+
# call to `Shiny.setInputValue("jster_initialized", true)` due to changes in https://github.com/rstudio/shiny/pull/3666.
139+
# Current stance is that https://github.com/rstudio/shiny/issues/3780 will not be resolved, so we must make a work around.
140+
# This is done by delaying the initial call to `Shiny.setInputValue("jster_initialized", true)`
141+
# by using a dynamic UI that is invalidated on the first draw, and then actually rendered on the second draw.
142+
renderUI({
143+
shinyjster::shinyjster_js(
144+
"
145+
var jst = jster();
146+
jst.add(Jster.shiny.waitUntilStable);
147+
jst.add(function(done) {
148+
var wait = function() {
149+
var txt = $('#status').get(0).textContent;
150+
if (
151+
typeof txt == 'string' &&
152+
txt.length > 0 &&
153+
(txt.match(new RegExp('Pass|Fail')) ?? '').length > 0
154+
) {
155+
done();
156+
return;
157+
}
158+
setTimeout(wait, 100);
150159
}
151-
setTimeout(wait, 100);
152-
}
153-
wait();
154-
})
155-
jst.add(function() {
156-
Jster.assert.isEqual(
157-
$('#status').text().trim(),
158-
'Pass'
159-
)
160-
})
161-
jst.test();
162-
"
163-
)
160+
wait();
161+
})
162+
jst.add(function() {
163+
Jster.assert.isEqual(
164+
$('#status').text().trim(),
165+
'Pass'
166+
)
167+
})
168+
jst.test();
169+
"
170+
)
171+
})
164172
165173
shinyjster::shinyjster_server(input, output)
166174
```

0 commit comments

Comments
 (0)