how to know when a value in a db changes

723 vistas
Ir al primer mensaje no leído

James Bird

no leída,
21 may 2015, 9:51:13 a.m.21/5/15
para shiny-...@googlegroups.com

This is a general question on linking objects in a Shiny app to a database table. What is the best approach to ensure the object in shiny is updated when the table in the db is modified? If we build a reactive table in shiny based on a db table, does it know when the db table changes?

e.g.
getPTI4Journal <- function() {
out <- tryCatch(
{
sqlquery <- "select PTI1,PTI2,PTI4,MODELSELECTED,VALUE, NOTE, CHANGED from DF_JOURNALPTI4"
jdbcConnection <- getJdbcConn()
#Reading from Oracle
dbGetQuery(jdbcConnection, sqlquery)

},

finally={
dbDisconnect(jdbcConnection)
}

Joe Cheng

no leída,
26 may 2015, 5:43:28 p.m.26/5/15
para James Bird,shiny-...@googlegroups.com
You can use the reactivePoll function for this.

Your checkFunction would be some kind of cheap-to-execute expression that would change when the data has changed, for example the result of the query "select MAX(CHANGED) from DF_JOURNALPTI4" (I'm just assuming that CHANGED is a timestamp field).

The valueFunction would be the query to get the actual data you want (in this case, getPTI4Journal).

You also provide a polling interval. reactivePoll will automatically execute your checkFunction once per polling interval, and if the returned value changes, it will execute the full valueFunction.

The return value of reactivePoll is a reactive expression (e.g. you call it like a function to retrieve its value) that represents the most recent valueFunction result.

I hope that makes sense...

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/fa97a88d-23a4-41eb-bed4-21b176dd0bdf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Bird

no leída,
29 may 2015, 10:49:47 a.m.29/5/15
para shiny-...@googlegroups.com
Thanks Joe!
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos