troubles with passing data to different dataframes with reactivity (i gues)

Hello,
original goal: i want to use shiny app to input data in some different dataframes eg data input from tab BASISGEGEVENS should come in dataframe INIT and datainput from tab GEWICHT should come in dataframe GEWICHT;
i wrote a code to do this but by testing it it all wrote the data of gewicht in all dataframes or crashed.


library(shiny)
##functies definities

saveData_init <- function(data1) {
  #used by initial files (personal fixed info)
  

  data_init <- as.data.frame(t(data1))

  if (exists("initfile")) {
    initfile<<- rbind(initfile, data_init)
  } else
    {
    initfile <<- data_init
    
    }}
#all function should write to a comparable different dataframe
saveData_gewicht <- function(data3) {
  #used by initial files (personal fixed info)
  
  
  data_gewicht <- as.data.frame(t(data3))
  
  if (exists("gewicht")) {
    gewicht<<- rbind(gewicht, data_gewicht)
  } else
  {
    gewicht <<- data_gewicht
    
  }}

 
  

loadData <- function() {
  if (exists("responses")) {
    responses
  }
}


# Define UI for application gezondheid input data and diagrams
ui <- fluidPage(
  
  titlePanel("GEZONDHEID"),
  
  navlistPanel(
    "INPUT : MEETRESULTATEN",
    tabPanel("BASISGEGEVENS ", 
             textInput("datumbasic", "Datum:", ""),#zoeken nr autofill datum
             textInput("gewichtbasic", "Gewicht:", ""),
             textInput("lengtebasic", "Lengte:", ""),
#knop om te verwerken
             actionButton("submitbasic", "submit")),
    tabPanel("BLOEDDRUK", 
             textInput("datumm", "Datum:", ""),
             textInput("onderdrukm", "Onderdruk:", ""),
             textInput("bovendrukm", "Bovendruk:", ""),
#knop om te verwerken
             actionButton("savebloed", "Save")),
    tabPanel("GEWICHT",
             textInput("datumgewicht", "Datum:", ""),
             textInput("kg", "Kg:", ""),
             textInput("uitleg", "uitleg:", ""),
#knop om te verwerken
             actionButton("savegewicht", "Save")),
    
    tabPanel("BLOEDONDERZOEK",
             textInput("datumbloedw", "Datum:", ""),
             textInput("nierenbl", "Nieren:", ""),
             textInput("leverbl", "Lever gammaCT:", ""),
             textInput("ldlbl", "Cholstrol ldl:", ""),
             textInput("hdlbl", "Cholstrol hdl:", ""),
#knop om te verwerken
             actionButton("bloedwaarden", "save")
             ),
    "MEDICATIE",
    tabPanel("SOORTEN",
             textInput("naammed", "Naam:", ""),
             textInput("functiemed", "Functie:", ""),
             textInput("dosismed", "Dosis:", ""),
#knop om te verwerken
             actionButton("savemedicatie", "Save")
             ),
             
    tabPanel("VOORRAAD",
             textInput("naamvo", "Naam geneesmiddel:", ""),
             textInput("aankoop", "Datum aanschaf:", ""),
#knop om te verwerken
             actionButton("savevoorraad", "Save")
             ),
    tabPanel("VACCINATIES",
             textInput("typevac", "Naam:", ""),
             textInput("datumvac", "Datum:", ""),
             textInput("duurvac", "Geldigheid:", ""),
#knop om te verwerken
             actionButton("savevaccin", "Save")
             ),
    
    tabPanel("Overzichten")
  )
)

# Define server logic required to draw a histogram
server <- function(input, output, session) {
  #input verwerking basisgevens OK
  fields1 <- c("datumbasic","gewichtbasic","lengtebasic")
  formData <- reactive({
    
      data1 <<- sapply(fields1, function(x) input[[x]])
      data1
  })
  # When the Submit button is clicked, save the form data
  observeEvent(input$submitbasic, {
    saveData_init(formData())
  })
  #input verwerking bloeddruk 
  fields2 <- c("datumm","onderdrukm","bovendrukm")
  formData <- reactive({
      data2 <- sapply(fields2, function(x) input[[x]])
      data2
  })
  # When the Submit button is clicked, save the form data
  observeEvent(input$savebloed, {
     
      saveData(formData())
  })
 
  
  #input verwerking gewicht 
  fields3 <- c("datumgewicht","kg","uitleg")
  formData3 <- reactive({
    data3 <- sapply(fields3, function(x) input[[x]])
    data3
  })
  # When the Submit button is clicked, save the form data
  observeEvent(input$savegewicht, {
      
     
      saveData_gewicht(formData3())
  })
  #input verwerking bloedonderzoek OK
  
  formData <- reactive({
      data <- sapply(fields, function(x) input[[x]])
      data
    
  })
  # When the Submit button is clicked, save the form data
  observeEvent(input$savebloedwaarden, {
      fields <- c("datumbloedon","nierenbl","leverbl","ldlbl","hdlbl")
      catfile <<- 4
      saveData(formData())
    
  })
 
  #input verwerking medicatie OK
  
  formData <- reactive({
    data <- sapply(fields, function(x) input[[x]])
    data
  })
  # When the Submit button is clicked, save the form data
  observeEvent(input$submit, {
    fields <- c("naammed","functievo","dosismed")
    catfile <<- 5
    saveData(formData())
    
  })
  #input verwerking voorraad medicatie OK
  
  formData <- reactive({
    data <- sapply(fields, function(x) input[[x]])
    data
  })
  # When the Submit button is clicked, save the form data
  observeEvent(input$submit, {
   
    fields <- c("naamvo","aankoop")
    catfile <<- 6
    saveData(formData())
  })
  #input verwerking vaccinaties OK
  
  formData <- reactive({
  
    data <- sapply(fields, function(x) input[[x]])
    data
  })
  # When the Submit button is clicked, save the form data
  observeEvent(input$submit, {
	fields <- c("typevac","datumvac","duurvac")
    catfile <<- 7
    saveData(formData())
  })

  # opmaak overzichtspagina
    }

# Run the application 
shinyApp(ui = ui, server = server)

can some one give advise?
Kind regards, Nobel

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.