I'm new to R shiny and I'm building a R shiny app that allows users to update values on a matrixInput. When that values are change the app update my datasets with the new information. I would like to have a button ("Reset Button") that allows to show the matrix with the values in their original form (ie with my original dataset when it opens for the first time in the app), but i would like to do that without close/open the app.
this is part of the code:
library(shiny)
library(shinyjs)
library(data.table)
ui:
shinyUI(pageWithSidebar(
headerPanel("title"),
sidebarPanel(conditionalPanel(condition="input.tabselected==1",
selectInput("equip_input", "Equip", choices=c("Total", equip_order)),
matrixInput("matrix_aux",
value = matrix_aux,
cols = list(names = TRUE)),
useShinyjs(),
actionButton("action_simulation", "Simulation"),
actionButton("reset_button","Reset")))))
And in the server i tried to "reload" my R environment, that's where i have the datasets without changes:
shinyServer(function(input,output, session)({
var_aux1 <- reactive({
table_input = as.matrix(input$matrix_aux)
var_aux1 = table_input[,2]
return (var_aux1)})
var_aux2 <- reactive({
table_input = as.matrix(input$matrix_aux)
var_aux2 = table_input[,3]
return (var_aux2) })
var_aux3 <- reactive({
table_input = as.matrix(input$matrix_aux)
var_aux3 = table_input[,4]
return (var_aux3)})
observeEvent(input$action_simulation, {
var_aux1 <- as.numeric(var_aux1())
var_aux2<- as.numeric(var_aux2())
var_aux3 <- as.numeric(var_aux3())
v1[(v1$Equip == as.character(input$equip_input),]$var1 <<- var_aux1
v1[(v1$Equip == as.character(input$equip_input),]$var2 <<- var_aux2
v1[(v1$Equip == as.character(input$equip_input),]$var3 <<- var_aux3
}
#this button doesn't do what i want
observeEvent(input$reset_button, {
rm(list=ls())
load("mydata") })}))
But it doesn't work. How can I do it??
Example:
When the user change the values in the matrix, the app updates my datasets with the new values:
observeEvent(input$action_simulation, {
v1[(v1$Equip == as.character(input$equip_input),]$var1 <<- var_aux1
v1[(v1$Equip == as.character(input$equip_input),]$var2 <<- var_aux2
v1[(v1$Equip == as.character(input$equip_input),]$var3 <<- var_aux3
}})
And I would like to have a option to make reset to the original values without changes