0

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

  • Hello, please include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), otherwise it is harder for other people to provide a solution to your problem – bretauv Apr 21 '22 at 07:11
  • this is better but still not enough. A reproducible example of a shiny app should include all the code that is necessary to reproduce the problem (but you need to keep the code minimal, meaning that you need to remove everything that is not related to the problem). If you want an example, check one of my [previous questions](https://stackoverflow.com/questions/56842812/r-shiny-display-text-as-code-on-several-lines). The code I provided was sufficient to have a working shiny app, and it was reused in the answer – bretauv Apr 21 '22 at 09:44
  • thank you! Ok now i think that there is all the code related to my question :) – Joana Silva Apr 21 '22 at 10:23
  • What is `equip_order`? We don't have access to your data – bretauv Apr 21 '22 at 11:50
  • Is a list of teams that the user can choose – Joana Silva Apr 21 '22 at 13:44

0 Answers0