Comments (5)
Hi @HugoGit39, thanks for the question! The main issue is that req()
throws an error that's normally handled gracefully by observers and reactives but that checkFunc
isn't designed to handle. You can read the reactive value in checkFunc
, though, so this pattern works:
USER_LOGGED_IN <- reactiveVal(FALSE)
observeEvent(input$login, {
message("User has logged in.")
# Pretend that the user has now logged in
USER_LOGGED_IN(TRUE)
})
# Function to poll for updated data every 30 seconds
data_poll <- reactivePoll(
intervalMillis = 5000,
session = session,
checkFunc = function() {
if (!USER_LOGGED_IN()) {
message("Not logged in yet.")
return()
}
# Return a timestamp to trigger polling
message("Data check: ", format(Sys.time(), "%H:%M:%S"))
format(Sys.time(), "%H:%M")
},
valueFunc = function() {
# Generate new data
req(USER_LOGGED_IN())
generate_data()
}
)
I've put this modification in a small shinylive app from your example.
from shiny.
@gadenbuie Thx!. But the checkFunc is running already from the start. Isnt there a way to start the checkFunc (or the reactivePoll function) when the user logs in?
from shiny.
@gadenbuie Thx!. But the checkFunc is running already from the start. Isnt there a way to start the checkFunc (or the reactivePoll function) when the user logs in?
No, the way that reactivePoll()
works is that checkFunc
should be a cheap and quick function that can be called repeatedly. Whenever its value changes, it gets a new value by calling valueFunc
.
The idea in my updated example is to have checkFunc
return immediately when the user isn't yet logged in. Because that's only checking an R object, it'll resolve immediately. So it's okay that it's running before the value of data_poll()
is actually used.
from shiny.
Right, but it its still a nice feature to have reactivePoll
start running after a certain period right? Does checkFunc
takes a lot of computing power on the server-side?
from shiny.
Right, but it its still a nice feature to have
reactivePoll
start running after a certain period right? DoescheckFunc
takes a lot of computing power on the server-side?
No, the code you use for checkFunc
should be as quick and simple as possible. The idea is that checkFunc
should run extremely quickly and be okay for Shiny to run more often than necessary without slowing down your app.
from shiny.
Related Issues (20)
- shiny > 1.8.0 breaks tags$button reactivity HOT 6
- Set outputOtions at assignment
- Long running Shiny app starts printing lots of "nothing to compact" messages HOT 2
- Allow `OnUnhandledError` to be scoped to modules
- Warning: Error in ggplot2::geom_boxplot: Problem while converting geom to grob.
- Nested future-promises lose reactive context
- Problem with chromote package HOT 1
- dynamically creating multiple server module objects results in duplicate named servers HOT 2
- Updating reactive value on a timer results on JS error
- The issue of setting updateSelectInput's selected parameter to null HOT 3
- Parent container created by `shiny::tabPanel()` not taking full vertical container space
- Shiny Getting Started Tutorial missing `textOutput('selectedVar')` from example HOT 2
- Feature request: Add option to change radioButtons appearance similar to actionButtons
- R Shiny does not open a model training in Python HOT 1
- App with no outputs never stops pulsing
- shiny app examples crashes without error HOT 7
- observeEvent does not trigger to changes in reactiveValues HOT 4
- Can't add another ExtendedTask while the one is running? HOT 1
- Busy indicator is only shown for 0.25s
- Progress bar properties cannot be cleared by setting `NULL`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shiny.