diff --git a/panels/C1_Visualize/2_visualize-panel-server.R b/panels/C1_Visualize/2_visualize-panel-server.R index ae7cd803..6ecabcfd 100644 --- a/panels/C1_Visualize/2_visualize-panel-server.R +++ b/panels/C1_Visualize/2_visualize-panel-server.R @@ -612,6 +612,11 @@ vis.par <- reactive({ # set ci_width in par for plots vis.par$ci.width <- ci_width() / 100 + # cat("\n\n===== looking at parameters ---- \n") + # cat("vis.par: \n") + # print(vis.par$trend) + # cat("\ngraphical.par: \n") + # print(graphical.par$trend) vis.par <- modifyList(reactiveValuesToList(graphical.par), vis.par, keep.null = TRUE ) @@ -1311,8 +1316,7 @@ output$mini.plot <- renderPlot({ }) ## Reset variable selection and graphical parameters. -observe({ - input$reset.graphics +observeEvent(input$reset.graphics, { if (!is.null(input$reset.graphics) && input$reset.graphics > 0) { isolate({ updateCheckboxInput(session, "show_boxplot_title", value = T) @@ -4197,6 +4201,7 @@ output$trend.curve.panel <- renderUI({ # title.add.trend.curve = h5("Add trend curves") trend.curves.title <- h5(strong("Trend Curves")) smoother.title <- h5(strong("Smoother")) + check.linear.object <- checkboxInput("check_linear", label = "linear", value = ifelse( @@ -4407,6 +4412,9 @@ observe({ input$color.linear input$type.linear isolate({ + # cat("\n---------------\n") + # cat("Doing some linear trend stuff ...\n") + # cat("input$check_linear: ", input$check_linear, "\n") if (!is.null(input$check_linear)) { if (input$check_linear) { if (length(which(graphical.par$trend %in% "linear")) == 0) { @@ -6939,99 +6947,160 @@ output$add.fitted.residuals.panel <- renderUI({ ret }) - observeEvent(input$store_fitted_values, { - existing_colnames = colnames(vis.data()) - if (!is.null(plot.par$x)) { - if (iNZightTools::is_num(vis.data()[[plot.par$x]]) && - !is.null(plot.par$x) && - iNZightTools::is_num(vis.data()[[plot.par$y]]) && !is.null(plot.par$y)) { - showModal(modalDialog( - h5(strong("Specify names for the new variables")), - conditionalPanel( - "input.check_linear", - fixedRow( - column(2, h5("Linear:")), - column(6, textInput( - inputId = "add_linear_fitted_values", - value = iNZightTools::make_names( - new = paste(input$vari1, ".predict.linear", sep = ""), - existing = existing_colnames - ), - label = NULL - )) + temp1 <- input$vari1 + temp2 <- input$vari2 + temp <- get.data.set() + existing_colnames <- colnames(temp) + if (iNZightTools::is_num(vis.data()[[plot.par$x]]) && + !is.null(plot.par$x) && + iNZightTools::is_num(vis.data()[[plot.par$y]]) && + !is.null(plot.par$y)) { + linear_trend <- FALSE + quadratic_trend <- FALSE + cubic_trend <- FALSE + smoother_trend <- FALSE + if ("linear" %in% graphical.par$trend) { + linear_trend <- TRUE + fit.linear <- with( + vis.par(), + lm(vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], + na.action = na.exclude + ) + ) + pred.linear <- data.frame( + predict(fit.linear, + newdata = data.frame( + x = vis.data()[[plot.par$y]], + stringsAsFactors = TRUE ) ), - conditionalPanel( - "input.check_quadratic", - fixedRow( - column(2, h5("Quadratic:")), - column(6, textInput( - inputId = "add_quadratic_fitted_values", - value = iNZightTools::make_names( - new = paste(input$vari1, ".predict.quadratic", sep = ""), - existing = existing_colnames - ), - label = NULL - )) + stringsAsFactors = TRUE + ) + + colnames(pred.linear) <- iNZightTools::make_names( + new = sprintf("%s.predict.by.%s.linear", input$vari1, input$vari2), + existing = existing_colnames + ) + temp <- cbind(temp, pred.linear) + } + if ("quadratic" %in% graphical.par$trend) { + quadratic_trend <- TRUE + fit.quadratic <- with( + vis.par(), + lm( + vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]] + + I(vis.data()[[plot.par$y]]^2), + na.action = na.exclude + ) + ) + pred.quadratic <- data.frame( + predict(fit.quadratic, + newdata = data.frame( + x = vis.data()[[plot.par$y]], + stringsAsFactors = TRUE ) ), - conditionalPanel( - "input.check_cubic", - fixedRow( - column(2, h5("Cubic:")), - column(6, textInput( - inputId = "add_cubic_fitted_values", - value = iNZightTools::make_names( - new = paste(input$vari1, ".predict.cubic", sep = ""), - existing = existing_colnames - ), - label = NULL - )) + stringsAsFactors = TRUE + ) + colnames(pred.quadratic) <- iNZightTools::make_names( + new = sprintf("%s.predict.by.%s.quadratic", input$vari1, input$vari2), + existing = existing_colnames + ) + temp <- cbind(temp, pred.quadratic) + } + if ("cubic" %in% graphical.par$trend) { + cubic_trend <- TRUE + fit.cubic <- with( + vis.par(), + lm( + vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]] + + I(vis.data()[[plot.par$y]]^2) + I(vis.data()[[plot.par$y]]^3), + na.action = na.exclude + ) + ) + pred.cubic <- data.frame( + predict(fit.cubic, + newdata = data.frame( + x = vis.data()[[plot.par$y]], + stringsAsFactors = TRUE ) ), - conditionalPanel( - "input.check_smoother", - fixedRow( - column(2, h5("Smoother:")), - column(6, textInput( - inputId = "add_smoother_fitted_values", - value = iNZightTools::make_names( - new = paste(input$vari1, ".predict.smoother", sep = ""), - existing = existing_colnames - ), - label = NULL - )) + stringsAsFactors = TRUE + ) + colnames(pred.cubic) <- iNZightTools::make_names( + new = sprintf("%s.predict.by.%s.cubic", input$vari1, input$vari2), + existing = existing_colnames + ) + temp <- cbind(temp, pred.cubic) + } + if (graphical.par$smooth > 0) { + temp3 <- graphical.par$smooth + smoother_trend <- TRUE + fit.smooth <- with( + vis.par(), + loess(vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], + span = graphical.par$smooth, + family = "gaussian", degree = 1, na.action = "na.exclude" + ) + ) + pred.smooth <- data.frame( + predict(fit.smooth, + newdata = data.frame( + x = vis.data()[[plot.par$y]], + stringsAsFactors = TRUE ) ), - actionButton("store_fitted_values_ok", "OK"), - textOutput("add_fitted_values_status"), - title = "Store fitted values" - )) + stringsAsFactors = TRUE + ) + colnames(pred.smooth) <- iNZightTools::make_names( + new = sprintf("%s.predict.by.%s.smoother", input$vari1, input$vari2), + existing = existing_colnames + ) + temp <- cbind(temp, pred.smooth) + } + } else { + if (iNZightTools::is_num(vis.data()[[plot.par$y]])) { + fit <- lm( + formula = + vis.data()[[plot.par$y]] ~ vis.data()[[plot.par$x]], + na.action = na.exclude + ) } else { - tmp_value = paste( - ifelse(iNZightTools::is_num(vis.data()[[plot.par$x]]), - input$vari1, input$vari2 - ), - ".predict", - sep = "" + fit <- lm( + formula = + vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], + na.action = na.exclude ) - showModal(modalDialog( - h5(strong("Specify names for the new variables")), - fixedRow(column(6, textInput( - inputId = "add_numcat_fitted_values", - value = iNZightTools::make_names(new = tmp_value, existing = existing_colnames), - label = NULL - ))), - actionButton("store_fitted_values_ok", "OK"), - textOutput("add_fitted_values_status"), - title = "Store fitted values" - )) } + pred.numcat <- data.frame( + predict(fit, newdata = data.frame( + x = ifelse(iNZightTools::is_num(vis.data()[[plot.par$x]]), + vis.data()[[plot.par$y]], vis.data()[[plot.par$x]] + ), + stringsAsFactors = TRUE + )), + stringsAsFactors = TRUE + ) + # colnames(pred.numcat) <- input$add_numcat_fitted_values + colnames(pred.numcat) <- iNZightTools::make_names( + new = sprintf( + "%s.predict.by.%s", + ifelse(iNZightTools::is_num(vis.data()[[plot.par$x]]), + input$vari1, input$vari2 + ), + ifelse(iNZightTools::is_num(vis.data()[[plot.par$x]]), + input$vari2, input$vari1 + ) + ), + existing = existing_colnames + ) + temp <- cbind(temp, pred.numcat) } + updatePanel$datachanged <- updatePanel$datachanged + 1 + values$data.set <- temp }) - output$add_fitted_values_status <- renderText({ if (!is.null(input$store_fitted_values_ok) && input$store_fitted_values_ok > 0) { @@ -7043,366 +7112,136 @@ output$add_fitted_values_status <- renderText({ observeEvent(input$store_residuals, { - existing_colnames = colnames(vis.data()) - if (iNZightTools::is_num(vis.data()[[plot.par$x]]) && !is.null(plot.par$x) && - iNZightTools::is_num(vis.data()[[plot.par$y]]) && !is.null(plot.par$y)) { - showModal(modalDialog( - h5(strong("Specify names for the new variables")), - conditionalPanel( - "input.check_linear", - fixedRow( - column(2, h5("Linear:")), - column(6, textInput( - inputId = "add_linear_residuals", - value = iNZightTools::make_names( - new = paste(input$vari1, ".residuals.linear", sep = ""), - existing = existing_colnames - ), - label = NULL - )) + existing_colnames <- colnames(vis.data()) + temp1 <- input$vari1 + temp2 <- input$vari2 + temp <- get.data.set() + if (iNZightTools::is_num(vis.data()[[plot.par$x]]) && + !is.null(plot.par$x) && + iNZightTools::is_num(vis.data()[[plot.par$y]]) && + !is.null(plot.par$y)) { + linear_trend <- FALSE + quadratic_trend <- FALSE + cubic_trend <- FALSE + smoother_trend <- FALSE + if ("linear" %in% graphical.par$trend) { + linear_trend <- TRUE + fit.linear <- with( + vis.par(), + lm(vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], + na.action = na.exclude ) - ), - conditionalPanel( - "input.check_quadratic", - fixedRow( - column(2, h5("Quadratic:")), - column(6, textInput( - inputId = "add_quadratic_residuals", - value = iNZightTools::make_names( - new = paste(input$vari1, ".residuals.quadratic", sep = ""), - existing = existing_colnames - ), - label = NULL - )) + ) + resi.linear <- data.frame(residuals(fit.linear), stringsAsFactors = TRUE) + colnames(resi.linear) <- iNZightTools::make_names( + new = sprintf("%s.residuals.by.%s.linear", input$vari1, input$vari2), + existing = existing_colnames + ) + temp <- cbind(temp, resi.linear) + } + if ("quadratic" %in% graphical.par$trend) { + quadratic_trend <- TRUE + fit.quadratic <- with( + vis.par(), + lm( + vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]] + + I(vis.data()[[plot.par$y]]^2), + na.action = na.exclude ) - ), - conditionalPanel( - "input.check_cubic", - fixedRow( - column(2, h5("Cubic:")), - column(6, textInput( - inputId = "add_cubic_residuals", - value = iNZightTools::make_names( - new = paste(input$vari1, ".residuals.cubic", sep = ""), - existing = existing_colnames - ), - label = NULL - )) + ) + resi.quadratic <- data.frame(residuals(fit.quadratic), stringsAsFactors = TRUE) + colnames(resi.quadratic) <- iNZightTools::make_names( + new = sprintf("%s.residuals.by.%s.quadratic", input$vari1, input$vari2), + existing = existing_colnames + ) + temp <- cbind(temp, resi.quadratic) + } + if ("cubic" %in% graphical.par$trend) { + cubic_trend <- TRUE + fit.cubic <- with( + vis.par(), + lm( + vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]] + + I(vis.data()[[plot.par$y]]^2) + I(vis.data()[[plot.par$y]]^3), + na.action = na.exclude ) - ), - conditionalPanel( - "input.check_smoother", - fixedRow( - column(2, h5("Smoother:")), - column(6, textInput( - inputId = "add_smoother_residuals", - value = iNZightTools::make_names( - new = paste(input$vari1, ".residuals.smoother", sep = ""), - existing = existing_colnames - ), - label = NULL - )) + ) + resi.cubic <- data.frame(residuals(fit.cubic), + stringsAsFactors = TRUE + ) + colnames(resi.cubic) <- iNZightTools::make_names( + new = sprintf("%s.residuals.by.%s.cubic", input$vari1, input$vari2), + existing = existing_colnames + ) + temp <- cbind(temp, resi.cubic) + } + if (graphical.par$smooth > 0) { + temp3 <- graphical.par$smooth + smoother_trend <- TRUE + fit.smooth <- with( + vis.par(), + loess(vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], + span = graphical.par$smooth, + family = "gaussian", degree = 1, na.action = "na.exclude" ) - ), - actionButton("store_resisuals_ok", "OK"), - textOutput("add_residuals_status"), - title = "Store residuals" - )) + ) + resi.smooth <- data.frame(residuals(fit.smooth), + stringsAsFactors = TRUE + ) + colnames(resi.smooth) <- iNZightTools::make_names( + new = sprintf("%s.residuals.by.%s.smoother", input$vari1, input$vari2), + existing = existing_colnames + ) + temp <- cbind(temp, resi.smooth) + } + # if (linear_trend) { + # updateCheckboxInput(session, "check_linear", value = T) + # } + # if (quadratic_trend) { + # updateCheckboxInput(session, "check_quadratic", value = T) + # } + # if (cubic_trend) { + # updateCheckboxInput(session, "check_cubic", value = T) + # } + # if (smoother_trend) { + # updateCheckboxInput(session, "check_smoother", value = T) + # updateSliderInput(session, "smoother.smooth", value = temp3) + # } } else { - tmp_value = paste( - ifelse(iNZightTools::is_num(vis.data()[[plot.par$x]]), - input$vari1, input$vari2 + if (iNZightTools::is_num(vis.data()[[plot.par$y]])) { + fit <- lm( + formula = + vis.data()[[plot.par$y]] ~ vis.data()[[plot.par$x]], + na.action = na.exclude + ) + } else { + fit <- lm( + formula = + vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], + na.action = na.exclude + ) + } + resi.numcat <- data.frame(residuals(fit), stringsAsFactors = TRUE) + colnames(resi.numcat) <- iNZightTools::make_names( + new = sprintf( + "%s.residuals.by.%s", + ifelse(iNZightTools::is_num(vis.data()[[plot.par$x]]), + input$vari1, input$vari2 + ), + ifelse(iNZightTools::is_num(vis.data()[[plot.par$x]]), + input$vari2, input$vari1 + ) ), - ".residuals", - sep = "" + existing = existing_colnames ) - showModal(modalDialog( - h5(strong("Specify names for the new variables")), - fixedRow(column(6, textInput( - inputId = "add_numcat_residuals", - value = iNZightTools::make_names(new = tmp_value, existing = existing_colnames), - label = NULL - ))), - actionButton("store_resisuals_ok", "OK"), - textOutput("add_residuals_status"), - title = "Store residuals" - )) - } -}) - - -output$add_residuals_status <- renderText({ - if (!is.null(input$store_resisuals_ok) && - input$store_resisuals_ok > 0) { - "Add succesful" - } else { - NULL + temp <- cbind(temp, resi.numcat) } + updatePanel$datachanged <- updatePanel$datachanged + 1 + values$data.set <- temp + updateCheckboxInput(session, "vari1", value = temp1) + updateCheckboxInput(session, "vari2", value = temp2) }) -observe({ - input$store_resisuals_ok - isolate({ - if (!is.null(input$store_resisuals_ok) && - input$store_resisuals_ok > 0) { - temp1 <- input$vari1 - temp2 <- input$vari2 - temp <- get.data.set() - if (iNZightTools::is_num(vis.data()[[plot.par$x]]) && - !is.null(plot.par$x) && - iNZightTools::is_num(vis.data()[[plot.par$y]]) && - !is.null(plot.par$y)) { - linear_trend <- FALSE - quadratic_trend <- FALSE - cubic_trend <- FALSE - smoother_trend <- FALSE - if ("linear" %in% graphical.par$trend) { - linear_trend <- TRUE - fit.linear <- with( - vis.par(), - lm(vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], - na.action = na.exclude - ) - ) - resi.linear <- data.frame(residuals(fit.linear), stringsAsFactors = TRUE) - colnames(resi.linear) <- input$add_linear_residuals - temp <- cbind(temp, resi.linear) - } - if ("quadratic" %in% graphical.par$trend) { - quadratic_trend <- TRUE - fit.quadratic <- with( - vis.par(), - lm( - vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]] + - I(vis.data()[[plot.par$y]]^2), - na.action = na.exclude - ) - ) - resi.quadratic <- data.frame(residuals(fit.quadratic), stringsAsFactors = TRUE) - colnames(resi.quadratic) <- input$add_quadratic_residuals - temp <- cbind(temp, resi.quadratic) - } - if ("cubic" %in% graphical.par$trend) { - cubic_trend <- TRUE - fit.cubic <- with( - vis.par(), - lm( - vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]] + - I(vis.data()[[plot.par$y]]^2) + I(vis.data()[[plot.par$y]]^3), - na.action = na.exclude - ) - ) - resi.cubic <- data.frame(residuals(fit.cubic), - stringsAsFactors = TRUE - ) - colnames(resi.cubic) <- input$add_cubic_residuals - temp <- cbind(temp, resi.cubic) - } - if (graphical.par$smooth > 0) { - temp3 <- graphical.par$smooth - smoother_trend <- TRUE - fit.smooth <- with( - vis.par(), - loess(vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], - span = graphical.par$smooth, - family = "gaussian", degree = 1, na.action = "na.exclude" - ) - ) - resi.smooth <- data.frame(residuals(fit.smooth), - stringsAsFactors = TRUE - ) - colnames(resi.smooth) <- input$add_smoother_residuals - temp <- cbind(temp, resi.smooth) - } - if (linear_trend) { - updateCheckboxInput(session, "check_linear", value = T) - } - if (quadratic_trend) { - updateCheckboxInput(session, "check_quadratic", value = T) - } - if (cubic_trend) { - updateCheckboxInput(session, "check_cubic", value = T) - } - if (smoother_trend) { - updateCheckboxInput(session, "check_smoother", value = T) - updateSliderInput(session, "smoother.smooth", value = temp3) - } - } else { - if (iNZightTools::is_num(vis.data()[[plot.par$y]])) { - fit <- lm( - formula = - vis.data()[[plot.par$y]] ~ vis.data()[[plot.par$x]], - na.action = na.exclude - ) - } else { - fit <- lm( - formula = - vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], - na.action = na.exclude - ) - } - resi.numcat <- data.frame(residuals(fit), stringsAsFactors = TRUE) - colnames(resi.numcat) <- input$add_numcat_residuals - temp <- cbind(temp, resi.numcat) - } - updatePanel$datachanged <- updatePanel$datachanged + 1 - values$data.set <- temp - updateCheckboxInput(session, "vari1", value = temp1) - updateCheckboxInput(session, "vari2", value = temp2) - } - }) -}) - -observe({ - input$store_fitted_values_ok - isolate({ - if (!is.null(input$store_fitted_values_ok) && - input$store_fitted_values_ok > 0) { - temp1 <- input$vari1 - temp2 <- input$vari2 - temp <- get.data.set() - if (iNZightTools::is_num(vis.data()[[plot.par$x]]) && - !is.null(plot.par$x) && - iNZightTools::is_num(vis.data()[[plot.par$y]]) && - !is.null(plot.par$y)) { - linear_trend <- FALSE - quadratic_trend <- FALSE - cubic_trend <- FALSE - smoother_trend <- FALSE - if ("linear" %in% graphical.par$trend) { - linear_trend <- TRUE - fit.linear <- with( - vis.par(), - lm(vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], - na.action = na.exclude - ) - ) - pred.linear <- data.frame( - predict(fit.linear, - newdata = data.frame( - x = vis.data()[[plot.par$y]], - stringsAsFactors = TRUE - ) - ), - stringsAsFactors = TRUE - ) - colnames(pred.linear) <- input$add_linear_fitted_values - temp <- cbind(temp, pred.linear) - } - if ("quadratic" %in% graphical.par$trend) { - quadratic_trend <- TRUE - fit.quadratic <- with( - vis.par(), - lm( - vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]] + - I(vis.data()[[plot.par$y]]^2), - na.action = na.exclude - ) - ) - pred.quadratic <- data.frame( - predict(fit.quadratic, - newdata = data.frame( - x = vis.data()[[plot.par$y]], - stringsAsFactors = TRUE - ) - ), - stringsAsFactors = TRUE - ) - colnames(pred.quadratic) <- input$add_quadratic_fitted_values - temp <- cbind(temp, pred.quadratic) - } - if ("cubic" %in% graphical.par$trend) { - cubic_trend <- TRUE - fit.cubic <- with( - vis.par(), - lm( - vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]] + - I(vis.data()[[plot.par$y]]^2) + I(vis.data()[[plot.par$y]]^3), - na.action = na.exclude - ) - ) - pred.cubic <- data.frame( - predict(fit.cubic, - newdata = data.frame( - x = vis.data()[[plot.par$y]], - stringsAsFactors = TRUE - ) - ), - stringsAsFactors = TRUE - ) - colnames(pred.cubic) <- input$add_cubic_fitted_values - temp <- cbind(temp, pred.cubic) - } - if (graphical.par$smooth > 0) { - temp3 <- graphical.par$smooth - smoother_trend <- TRUE - fit.smooth <- with( - vis.par(), - loess(vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], - span = graphical.par$smooth, - family = "gaussian", degree = 1, na.action = "na.exclude" - ) - ) - pred.smooth <- data.frame( - predict(fit.smooth, - newdata = data.frame( - x = vis.data()[[plot.par$y]], - stringsAsFactors = TRUE - ) - ), - stringsAsFactors = TRUE - ) - colnames(pred.smooth) <- input$add_smoother_fitted_values - temp <- cbind(temp, pred.smooth) - } - if (linear_trend) { - updateCheckboxInput(session, "check_linear", value = T) - } - if (quadratic_trend) { - updateCheckboxInput(session, "check_quadratic", value = T) - } - if (cubic_trend) { - updateCheckboxInput(session, "check_cubic", value = T) - } - if (smoother_trend) { - updateCheckboxInput(session, "check_smoother", value = T) - updateSliderInput(session, "smoother.smooth", value = temp3) - } - } else { - if (iNZightTools::is_num(vis.data()[[plot.par$y]])) { - fit <- lm( - formula = - vis.data()[[plot.par$y]] ~ vis.data()[[plot.par$x]], - na.action = na.exclude - ) - } else { - fit <- lm( - formula = - vis.data()[[plot.par$x]] ~ vis.data()[[plot.par$y]], - na.action = na.exclude - ) - } - pred.numcat <- data.frame( - predict(fit, newdata = data.frame( - x = ifelse(iNZightTools::is_num(vis.data()[[plot.par$x]]), - vis.data()[[plot.par$y]], vis.data()[[plot.par$x]] - ), - stringsAsFactors = TRUE - )), - stringsAsFactors = TRUE - ) - colnames(pred.numcat) <- input$add_numcat_fitted_values - temp <- cbind(temp, pred.numcat) - } - updatePanel$datachanged <- updatePanel$datachanged + 1 - values$data.set <- temp - updateCheckboxInput(session, "vari1", value = temp1) - updateCheckboxInput(session, "vari2", value = temp2) - } - }) -}) - - ## switch variables selected observeEvent(input$switch1, { if (!is.null(input$vari2) && input$vari2 != "none") { diff --git a/panels/C1_Visualize/infoWindow.R b/panels/C1_Visualize/infoWindow.R index a4e189a2..95f53975 100644 --- a/panels/C1_Visualize/infoWindow.R +++ b/panels/C1_Visualize/infoWindow.R @@ -194,31 +194,32 @@ observe({ updateCheckboxInput(session, inputId = "inf.trend.cubic", label = "cubic", value = input$check_cubic) }) -observe({ - input$inf.trend.linear - isolate({ - # graphical.par$bs.inference = F - # graphical.par$inference.type = NULL - if (is.null(input$check_linear) && !is.null(input$inf.trend.linear)) { - if (input$inf.trend.linear) { - if (length(which(graphical.par$trend %in% "linear")) == 0) { - graphical.par$trend <- c(graphical.par$trend, "linear") - } - graphical.par$col.trend[["linear"]] <- "blue" - graphical.par$lty.trend[["linear"]] <- 1 - } else { - if (length(which(graphical.par$trend %in% "linear")) > 0) { - graphical.par$trend <- graphical.par$trend[-which(graphical.par$trend %in% "linear")] - if (length(graphical.par$trend) == 0) { - graphical.par$trend <- NULL - } +observeEvent(input$inf.trend.linear, { + # graphical.par$bs.inference = F + # graphical.par$inference.type = NULL + # cat("\n---update inf.trend.linear ---\n") + # cat("input$inf.trend.linear: ", input$inf.trend.linear, "\n") + # cat("graphical.par$trend: ", graphical.par$trend, "\n") + if (is.null(input$check_linear) && !is.null(input$inf.trend.linear)) { + if (input$inf.trend.linear) { + if (length(which(graphical.par$trend %in% "linear")) == 0) { + graphical.par$trend <- c(graphical.par$trend, "linear") + } + graphical.par$col.trend[["linear"]] <- "blue" + graphical.par$lty.trend[["linear"]] <- 1 + } else { + if (length(which(graphical.par$trend %in% "linear")) > 0) { + graphical.par$trend <- graphical.par$trend[-which(graphical.par$trend %in% "linear")] + if (length(graphical.par$trend) == 0) { + graphical.par$trend <- NULL } } } - }) + } }) + observe({ input$inf.trend.quadratic isolate({ @@ -550,6 +551,7 @@ output$visualize.inference <- renderPrint({ if (!is.null(plot.par$x) && iNZightTools::is_num(vis.data()[[plot.par$x]]) && !is.null(plot.par$y) && iNZightTools::is_num(vis.data()[[plot.par$y]])) { chosen <- c(input$inf.trend.linear, input$inf.trend.quadratic, input$inf.trend.cubic) + # cat("chosen: ", chosen, "\n") curSet$trend <- if (any(chosen)) c("linear", "quadratic", "cubic")[chosen] else NULL } @@ -673,7 +675,7 @@ output$visualize.summary <- renderPrint({ vartypes$y <- iNZightTools::vartype(vis.data()[[curSet$y]]) } } - + if (!is.null(design_params$design$dataDesign)) { curSet$data <- NULL curSet$design <- as.name(".design") @@ -683,7 +685,7 @@ output$visualize.summary <- renderPrint({ # assign(designname, curMod$createSurveyObject(), envir = env) } .dataset <- get.data.set() - + if (!is.null(parseQueryString(session$clientData$url_search)$debug) && tolower(parseQueryString(session$clientData$url_search)$debug) %in% "true") { tryCatch({