3

I have a general question concerning reactive values and global variables in Shiny. My goal is to enter values into a dataframe in different reactive environments and the dataframe should always be up-to-date. I don't actually need environments to react on my dataframe like they do on other inputs. I would proceed as follows: Create a global dataframe in the beginning and enter the values using "<<-". I don't see any reason to use reactive values here. However, I am quite new to Shiny and would very much appreciate your opinion on this issue.

Patrick Balada
  • 1,330
  • 1
  • 18
  • 37
  • Why do you need such a global dataframe which is not (?) used in any reactive function? Where and when do you read this variable? Can you post an example? Anyway, global variables should be avoided whenever possible. Usually, it is possible. – Patrick Roocks Aug 03 '16 at 08:49
  • @ Patrick Roocks. Thank you for your comment. I guess my question was a little been unclear. Actually, I want to enter values into the dataframe in different reactive functions but it's not like a reactive function has to react on the event of a change in the dataframe (like eventReactive()). The crucial thing to me is that the dataframe is always up-to-date and I can use this values in different reactive environments. Do you understand what I mean? – Patrick Balada Aug 03 '16 at 08:53
  • 1
    An "up-to-date value" used in reactive function should be reactive from my understanding. In this question I got some help to eliminate a global variable using reactiveValues: http://stackoverflow.com/questions/33722757/update-handsontable-by-editing-table-and-or-eventreactive – Patrick Roocks Aug 03 '16 at 09:16
  • Instead of using a global variable, I would recommend you define your data frame within a `reactiveValues` call. – Benjamin Aug 03 '16 at 10:00
  • Adding a global variable in `global.R` will have the effect of exposing it to all users. If your app is used by more than one user they potential will be updating the global variable concurrently. – jdharrison Aug 03 '16 at 12:06
  • 1
    Your global data frame is going to be always "up-to-date" due to `<<-`. However, shiny is not going to see these updates and the code that depend on this data frame is not going to be re-evaluated. – Michal Majka Aug 03 '16 at 12:17

1 Answers1

-1

How do you propose to keep your database up to date? If you are building an app for the updating database, you have to provide user input for it.

If your database updation has a dependency on user input, then your database has to be reactive, so as to react to user inputs.

Code will have following structure:

ui <- shinyUI(pageWithSidebar(
mainPanel(selectInput())))

server <- shinyServer(function(input, output, session) {
database_update <- function(input$user_input)
}
vaibhavnag
  • 19
  • 4