Skip to content

Commit

Permalink
Implement possibility to obtain code (Closes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stan125 committed Sep 3, 2017
1 parent ef06b10 commit f975c2e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: bamlss.vis
Type: Package
Title: Visualize bamlss models in an interactive way.
Version: 0.3.0
Version: 0.4.0
Authors@R: person("Stanislaus", "Stadlmann", email = "stanislaus@stadlmann.cm", role = c("cre", "ctb"))
Maintainer: Stanislaus Stadlmann <stanislaus@stadlmann.cm>
Depends:
Expand All @@ -11,7 +11,8 @@ Depends:
Imports:
ggplot2 (>= 2.2.1),
rhandsontable (>= 0.3.4),
tidyr (>= 0.6.3)
tidyr (>= 0.6.3),
rstudioapi (>= 0.6)
Description: bamlss.vis calls a Shiny app where one can compare different predictions depending on varying covariate values.
License: GPL-2
LazyData: TRUE
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export(vis)
import(bamlss)
import(ggplot2)
import(rhandsontable)
import(rstudioapi)
import(shiny)
importFrom(tidyr,gather)
34 changes: 34 additions & 0 deletions R/vis.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' package.
#' @import shiny
#' @import rhandsontable
#' @import rstudioapi
#' @export

### --- Shiny App --- ###
Expand Down Expand Up @@ -272,10 +273,43 @@ vis <- function() {
selectInput("type_choices", label = "PDF or CDF?",
choices = c("pdf", "cdf"))

# Action Button for console pasting
ui_list[[3]] <-
actionButton("pastecode", icon = icon("code"),
label = "Obtain Code!", style = "color:white;
background-color:red")
ui_list
}
})

## What happens when pastecode button is pressed
observeEvent(input$pastecode,{
# First line of code
c_data <- capture.output(dput(pred$data))
c_data <- c("covariate_data <- ", c_data)
c_data <- paste0(c_data, collapse = "")

# Second line of code
c_predictions <- call("preds", model = as.name(input$model),
newdata = quote(covariate_data))
c_predictions <- paste0("pred_data <- ", deparse(c_predictions))

# Third line of code
c_plot <- call("plot_dist", model = as.name(input$model),
predictions = quote(pred_data),
type = input$type_choices)
if (!is.null(input$palette))
c_plot[["palette"]] <- input$palette
c_plot <- deparse(c_plot) # Make call into character

# Put everything together
command <- paste(c_data, c_predictions, c_plot, sep = "\n")

# Send to Console
sendToConsole(command, execute = FALSE)
})


# output$testprint <- renderPrint({
# if (!is.null(pred$data))
# pred$data
Expand Down
4 changes: 4 additions & 0 deletions inst/rstudio/addins.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name: BAMLSS Model Visualizer
Description: Shiny App to interactively display bamlss predictions.
Binding: vis
Interactive: true

0 comments on commit f975c2e

Please sign in to comment.