I'm wondering if it's possible for a shiny app that's not run on the web (i.e. it's only run by a user launching it from their R session) to assign values to objects in the user's global environment. For example, suppose that as part of the app a data.frame is generated and, instead of using a download button to save the data.frame to a file, is it possible to assign it to an object in the user's R session so that when they close the app the data.frame is available to them?
What about automatically save the entire environment (using "save" function) to a temporary file? Then, you can just load it (using "load" function) and your data frame will be in the environment. All this process can be easily automated, without needing to use any save button.
Related
I work on a Shiny app with multiple reactive variables as well as output objects scattered in numerous tabItems.
The idea behind this app is that on the first page you download a selected dataset, through an action button, that will be used by the entire app. After having created multiple reactive values and output objects when the user will explore the app, I would like to know if there is a simple way to re-initialize the application (reactive variables, output objects) as soon as we download another dataset thanks to the previous action button I have mentionned earlier.
In fact, I want to delete the value of reactive variables and output objects from the memory every time I click on this specific button and DL a new dataset.
I want this app to be the same as it is when I launch my code for the first time.
Regards
Thibaut
I tried to use reactive values a lot but it has to be done for every variables.
Perhaps, there is a simpler way.
I have an R shiny app that allows users to upload a dataset, interactively subset it and then save it to the server. I also have several test files that are structured just like the files expected from the future users. I would like to write an automated testing script that uploads one of the datasets, randomly subsets the table (selecting rows in datatable, clicking action buttons) and then clicks a button to save it to the server. The user input to the app should be partly random and I need the clickstream of the user as an output to compare it to the saved dataset.
Is there a way to do this with shinytest or is that just for predefined clickstreams?
I've created a shiny app that creates a graph based on data that's entered in daily via a shared excel sheet (.xlsx) that is in a shared folder (an L drive).
How would I format or upload the data so that it is able to be refreshed whenever a new daily line of data is entered?
Here is one possible approach along with reference documentations:
Create a workflow to fetch the data using its URL:
read in online xlsx - sheet in R
Make the data retrieval process reactive:
https://shiny.rstudio.com/articles/reactivity-overview.html
Set a reactiveTimer to periodically check for updates:
https://shiny.rstudio.com/reference/shiny/1.0.0/reactiveTimer.html
By doing so, your app will fetch the document on a regular basis to update your graph. If you want real time updates (i.e. every time there is a change in the document), you have to be able to trigger the application from outside, which is more complicated (especially via Excel).
Update:
Following up your comment; you don't need the data to be online. You are fine if you are able to import it into R. Just make this process reactive and set a timer to refresh everyday (see the documentation for examples). Alternatively you can have an actionButton to refresh manually.
I am attempting to refresh data from excel csv files as well as from webservice calls for a shiny app that i created. I understand the concept of invalidate later and reactivevalues(). However, there are many dataframes that rely on the initial ones created from the csv files and webservice calls and in order to update all of the downstream lists and dataframes I would have to put them all within observe blocks, make them globally defined since they are not within the server block, and prepend values$data to each dataframe - assuming I initialized values <- reactivevalues(). Is there an easier way to go about this to make sure all downstream dataframes are updated?
I am trying to determine if I am able to keep data in-memory with RStudio to be used by multiple sessions, or for the session to at least be preserved. Searching for information about the existence/nonexistence of this feature has proven to be challenging.
The test is this:
In a session with RStudio create a variable and assign a value to it.
In another session run a script that refers to that variable.
If the variable is assigned a value then the script will work, otherwise it fails with "Error: object variable not found.
Is it possible to make a cross session variable in Rstudio Server that will work with this procedure without engaging file i/o? Or is it simply unavailable as a server function?
Unfortunately this is not possible because of the way R itself is designed.
Each R session has its own private memory space which contains values and data (the global environment for that session, etc.).
In order to create a cross-session variable, the R sessions would have to share memory, and they would also have to coordinate access to that memory, so that (for instance) if one session was changing the value of the variable, the other session could not read the value until the first session was done changing it. This sort of coordination mechanism just doesn't exist in R.
If you want to do this there are a couple work-arounds:
Keep your data in a place that both sessions can read and write to safely, for instance in a database, or
As you mentioned, engaging file I/O is an option, but this isn't too hard: use a .Rdata file; when you wish to publish data to other sessions, write the private variables as an R data file (using e.g. save), and when the other session wishes to synchronize, it can load the data into its own private space (using e.g. load).