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)
- Unnesting an reactive Value to GGplot breaks HOT 1
- reactives running and trigger observers without open the tab
- Shiny is not releasing memory HOT 2
- Can't Open Chrome Driver in shinyapps.io
- Load plot upon launching Shiny app HOT 1
- shiny.autoreload does not work when runApp is given shinyApp result or a list HOT 1
- selectInput not working anymore within renderDataTable in 1.8.0 HOT 2
- Reactive selectizeInput box fail to update correctly in Shiny 1.8.0, first value of previous allowed choices are kept HOT 2
- Update jQuery version to 3.7.1
- 'make' not found HOT 3
- v1.8.0: Unable to highlight multiple selected values at once in selectInput/selectizeInput HOT 1
- How to use `Shiny.bindAll` for a DT table? HOT 8
- Why updateDateInput() nor dateRangeInput() don't have the datesdisabled parameter enabled? HOT 1
- Error in init.ts when using library(jsTreeR) HOT 3
- Shiny server not supporting http range requests. This disables seekbars for locally (www folder) hosted media files. HOT 2
- `accordion_insert_panel` on restored bookmarks does not work with a module HOT 3
- Nginx configuration
- When the withProgress is closed, the program still runs in the background. HOT 3
- Update bundled DataTable.js; deprecate `dataTableOutput()` HOT 4
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.