Skip to content

Commit

Permalink
Added option to restore last script
Browse files Browse the repository at this point in the history
  • Loading branch information
loye16 committed Sep 7, 2023
1 parent 7c77a8a commit e882d9f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion UIs/ui_run_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ run_analysis_tab <-
status = "danger",
solidHeader = TRUE,
# Select script type
actionButton("restore_last_script", "Restore previous script?"),
helpText(" "),
radioButtons("DC_script_mode",
"File type for generated script",
c("R", "R Markdown", "Matlab"),
Expand All @@ -23,7 +25,7 @@ run_analysis_tab <-
#Running
actionButton("DC_run_script", "Run and save the script"),
uiOutput("DC_scriptize_error"),
helpText(""),
helpText(" "),
actionButton("DC_save_decoding", "Save the script only"),
uiOutput("DC_save_decoding_error"))),
column(width = 8,
Expand Down
9 changes: 9 additions & 0 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ myServer <- function(input,output,session){
# Find which ids to signal eventReactive to check if they are in position
rv$decoding_para_id_computed <- 1

# Restoring last script
rv$curr_ace_editor_script <- " "
rv$curr_include_comments <- FALSE
rv$curr_script_mode <- "R"
rv$prev_ace_editor_script <- " "
rv$prev_include_comments <- FALSE
rv$prev_script_mode <- "R"


################################################################################
############################ Server source files ###############################
################################################################################
Expand Down
45 changes: 45 additions & 0 deletions servers/server_run_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,48 @@ observeEvent(input$DC_run_script,{




#### TEST
# Saving the previous state only when entering run analysis tab,
# changing the mode or comments, or manual edits are made
observeEvent(input$ace_editor_script, {
# This if statement is crucial or it will override the prev each
# time you change tabs
if(input$decoding_tabs == "Run Analysis"){
# Save the script mode
rv$prev_script_mode <- rv$curr_script_mode
rv$curr_script_mode <- input$DC_script_mode

# Save the comment selection
rv$prev_include_comments <- rv$curr_include_comments
rv$curr_include_comments <- input$include_comments

# Save the last script on editor
rv$prev_ace_editor_script <- rv$curr_ace_editor_script
rv$curr_ace_editor_script <- input$ace_editor_script
}
})

# Restoring the previous script
observeEvent(input$restore_last_script, {
# Changing the tab options to match the last output
# First two need to be wrapped in if statements otherwise the default of shiny
# will be to pick anything but the correct value, maybe they will change that
if(rv$prev_script_mode != input$DC_script_mode){
updateRadioButtons(session, "DC_script_mode", selected = rv$prev_script_mode)
}

if(rv$prev_include_comments != input$include_comments){
updateCheckboxInput(session, "include_comments", value = rv$prev_include_comments)
}

# Updating the ace scrip
if (rv$prev_script_mode == "Matlab") {
script_editor_mode <- "matlab"
} else {
script_editor_mode <- "r"
}
updateAceEditor(session, "ace_editor_script", rv$prev_ace_editor_script,
mode = script_editor_mode)
})

0 comments on commit e882d9f

Please sign in to comment.