From d216d802de6be0b15bc0193402df29002a080d73 Mon Sep 17 00:00:00 2001 From: dmattek Date: Tue, 8 Oct 2019 12:54:54 +0200 Subject: [PATCH] Changed checks for NULL data to validate-need syntax. --- modules/distPlot.R | 27 ++++++++------------------- modules/tabScatter.R | 34 +++++++++------------------------- modules/trajPlot.R | 25 +++++++++---------------- modules/trajRibbonPlot.R | 22 +++++++--------------- 4 files changed, 33 insertions(+), 75 deletions(-) diff --git a/modules/distPlot.R b/modules/distPlot.R index 4b01978..6b275f8 100644 --- a/modules/distPlot.R +++ b/modules/distPlot.R @@ -168,12 +168,6 @@ modDistPlot = function(input, output, session, # Boxplot - display output$outPlotBox = renderPlot({ - locBut = input$butPlot - - if (locBut == 0) { - cat(file = stderr(), 'boxPlot:Go button not pressed\n') - return(NULL) - } plotBox() @@ -181,12 +175,6 @@ modDistPlot = function(input, output, session, output$outPlotBoxInt = renderPlotly({ - locBut = input$butPlot - - if (locBut == 0) { - cat(file = stderr(), 'boxPlot:Go button not pressed\n') - return(NULL) - } # This is required to avoid # "Warning: Error in : cannot open file 'Rplots.pdf'" @@ -222,14 +210,15 @@ modDistPlot = function(input, output, session, plotBox <- function() { cat(file = stderr(), 'plotBox\n') + locBut = input$butPlot - loc.dt = in.data() - - cat(file = stderr(), "plotBox: on to plot\n\n") - if (is.null(loc.dt)) { - cat(file = stderr(), 'plotBox: dt is NULL\n') - return(NULL) - } + # Check if main data exists + # Thanks to solate all mods in the left panel are delayed + # until clicking the Plot button + loc.dt = isolate(in.data()) + validate( + need(!is.null(loc.dt), "Nothing to plot. Load data first!") + ) cat(file = stderr(), 'plotBox:dt not NULL\n') diff --git a/modules/tabScatter.R b/modules/tabScatter.R index 5aef3f3..e29c6c2 100644 --- a/modules/tabScatter.R +++ b/modules/tabScatter.R @@ -130,7 +130,7 @@ tabScatterPlotUI <- checkboxInput(ns('plotInt'), 'Interactive Plot', value = FALSE), - actionButton(ns('butGoScatter'), 'Plot!'), + actionButton(ns('butPlot'), 'Plot!'), uiOutput(ns("plotInt_ui")), downPlotUI(ns('downPlotScatter'), "Download Plot") ) @@ -286,20 +286,18 @@ tabScatterPlot <- plotScatter <- function() { cat(file = stderr(), "plotScatter\n") + locBut = input$butPlot - # isolate because calculations & plotting take a while - # re-plotting done upon button press - loc.dt = isolate(data4scatterPlot()) - - cat("plotScatter on to plot\n\n") - if (is.null(loc.dt)) { - cat(file = stderr(), 'plotScatter: dt is NULL\n') - return(NULL) - } + # Check if main data exists + # Thanks to solate all mods in the left panel are delayed + # until clicking the Plot button + loc.dt = isolate(in.data()) + validate( + need(!is.null(loc.dt), "Nothing to plot. Load data first!") + ) cat(file = stderr(), 'plotScatter:dt not NULL\n') - p.out = LOCggplotScat( dt.arg = loc.dt, plotlab.arg = NULL, @@ -314,14 +312,6 @@ tabScatterPlot <- # Plot rendering ---- output$outPlotScatter <- renderPlot({ - locBut = input$butGoScatter - - if (locBut == 0) { - cat(file = stderr(), 'plotScatter: Go button not pressed\n') - - return(NULL) - } - plotScatter() }) @@ -331,12 +321,6 @@ tabScatterPlot <- # When running on a server. Based on: # https://github.com/ropensci/plotly/issues/494 - locBut = input$butGoScatter - if (locBut == 0) { - cat(file = stderr(), 'plotScatterInt Go button not pressed\n') - return(NULL) - } - if (names(dev.cur()) != "null device") dev.off() pdf(NULL) diff --git a/modules/trajPlot.R b/modules/trajPlot.R index bb3cacd..ebeae2d 100644 --- a/modules/trajPlot.R +++ b/modules/trajPlot.R @@ -79,6 +79,7 @@ modTrajPlotUI = function(id, label = "Plot Individual Time Series") { uiOutput(ns('uiPlotTraj')), br(), modTrackStatsUI(ns('dispTrackStats')), + br(), downPlotUI(ns('downPlotTraj'), "Download Plot") ) } @@ -238,26 +239,20 @@ modTrajPlot = function(input, output, session, plotTraj <- function() { cat(file = stderr(), 'plotTraj: in\n') - locBut = input$butPlotTraj - if (locBut == 0) { - cat(file = stderr(), 'plotTraj: Go button not pressed\n') - - return(NULL) - } + # make the f-n dependent on the button click + locBut = input$butPlotTraj - # check main data exists + # Check if main data exists + # Thanks to solate all mods in the left panel are delayed + # until clicking the Plot button loc.dt = isolate(in.data()) - - cat("plotTraj: on to plot\n\n") - if (is.null(loc.dt)) { - cat(file = stderr(), 'plotTraj: dt is NULL\n') - return(NULL) - } + validate( + need(!is.null(loc.dt), "Nothing to plot. Load data first!") + ) cat(file = stderr(), 'plotTraj: dt not NULL\n') - # check if stim data exists loc.dt.stim = isolate(in.data.stim()) @@ -267,8 +262,6 @@ modTrajPlot = function(input, output, session, cat(file = stderr(), 'plotTraj: dt.stim not NULL\n') } - - # Future: change such that a column with colouring status is chosen by the user # colour trajectories, if dataset contains mid.in column # with filtering status of trajectory diff --git a/modules/trajRibbonPlot.R b/modules/trajRibbonPlot.R index 9d922e4..f85e6fd 100644 --- a/modules/trajRibbonPlot.R +++ b/modules/trajRibbonPlot.R @@ -68,7 +68,7 @@ modTrajRibbonPlotUI = function(id, label = "Plot Individual Time Series") { uiOutput(ns('uiPlotTraj')), br(), modTrackStatsUI(ns('dispTrackStats')), - + br(), downPlotUI(ns('downPlotTraj'), "Download Plot") ) } @@ -232,24 +232,16 @@ modTrajRibbonPlot = function(input, output, session, cat(file = stderr(), 'plotTrajRibbon: in\n') locBut = input$butPlotTraj - if (locBut == 0) { - cat(file = stderr(), 'plotTrajRibbon: Go button not pressed\n') - - return(NULL) - } - - # check if main data exists + # Check if main data exists + # Thanks to solate all mods in the left panel are delayed + # until clicking the Plot button loc.dt = isolate(in.data()) - - cat("plotTrajRibbon: on to plot\n\n") - if (is.null(loc.dt)) { - cat(file = stderr(), 'plotTrajRibbon: dt is NULL\n') - return(NULL) - } + validate( + need(!is.null(loc.dt), "Nothing to plot. Load data first!") + ) cat(file = stderr(), 'plotTrajRibbon: dt not NULL\n') - # check if stim data exists loc.dt.stim = isolate(in.data.stim()) -- GitLab