How to create reactive value from non-user input

Say you created a shiny app where you 1) enter someone's twitter handle, 2) click a button and 3) see two text outputs populate on the webpage

Let's say the two text outputs are 1) the person's most recent tweet and 2) all the comments

Once you click the button, let's say the code pulls the most recent tweet and any comments. The tweet won't change but the comments may keep coming in. If we assume there was some loop in your code that was able to pull the number of comments every minute and save that to a variable, is there a way to make that variable "reactive". So when it goes from 4 comments to 5 comments, it reruns the renderText and displays all 5 comments instead of the 4 that existed when the user first clicked the button.

This would involve no user input changes (no slider, button click, etc) - simply a variable changing in the background that then triggers some re-rendering in the app's output (chart, text, etc)

Is something like this possible?

Kind Regards and thanks so much for the great Shiny tutorial videos,
Jason

Responding to myself as this link from the demo section seemed to offer a method to solve this.

https://shiny.rstudio.com/gallery/reactive-poll-and-file-reader.html

Essentially, it you could run some code in a loop that checked for the number of comments and save that data to a file. Then you could run the fileReader code to pull that data and when it changed from 4 to 5, it could then be set to rerun the renderText for all 5 comments now (4 + the new one).

Still wonder if there's a way omit the fileReader piece and set a reactive variable without saving/reading the number of comments to/from a file.

I think it should be very easy Jason
You make a reactive () whose content is from querying your API to get all comments. You can use invalidLater() function https://shiny.rstudio.com/reference/shiny/0.14/invalidateLater.html to get this to execute regularly.
If the textoutputs renderText references that reactive it will all be smooth sailing. note: renderText is automatically reactive so will rerended when shiny detects that it's reactive inputs change. That's the beauty of reactive style programming.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.