Skip to content

Commit

Permalink
Code review UI
Browse files Browse the repository at this point in the history
  • Loading branch information
nuest committed Jul 19, 2019
1 parent c795c39 commit 5d54092
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 206 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Expand Up @@ -56,7 +56,7 @@ Suggests:
remotes,
ggplot2,
lattice
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
Collate:
'Class-Instruction.R'
'Class-Add.R'
Expand Down Expand Up @@ -88,8 +88,8 @@ Collate:
'dockerfile.R'
'package-installation-bespoke.R'
'package-installation-methods.R'
'rstudio_containerit.R'
'utility-functions.R'
'utils.R'
'rstudio_containerit.R'
Remotes: github::r-hub/sysreqs,
github::richfitz/stevedore
13 changes: 10 additions & 3 deletions R/addin.R
@@ -1,12 +1,19 @@
interactive_addin = function() {
common_addin <- function() {
sys.source(pkg_file('scripts','common.R'))
}

fromSession_addin <- function() {
common_addin()
sys.source(pkg_file('scripts','package-interactive-session.R'))
}

fromfile_addin = function() {
fromFile_addin <- function() {
common_addin()
sys.source(pkg_file('scripts','package-load-file.R'))
}

fromexpressions_addin = function() {
fromExpressions_addin <- function() {
common_addin()
sys.source(pkg_file('scripts','package-expressions.R'))
}

Expand Down
2 changes: 1 addition & 1 deletion R/dockerfile.R
Expand Up @@ -422,7 +422,7 @@ dockerfileFromFile <- function(file,
stop("The given file is not inside the context directory!")

# make sure that the path is relative to context
rel_path <- .makeRelative(file, context)
rel_path <- .makeRelative(normalizePath(file), context)

# execute script / markdowns or read Rdata file to obtain sessioninfo
if (stringr::str_detect(string = file,
Expand Down
24 changes: 12 additions & 12 deletions inst/rstudio/addins.dcf
@@ -1,19 +1,19 @@
Name: From interactive session
Description: Create dockerfile from interactive session
Binding: interactive_addin
Name: Dockerfile from interactive session
Description: Create Dockerfile from an interactive session
Binding: fromSession_addin
Interactive: true

Name: From file
Description: Create dockerfile from file
Binding: fromfile_addin
Name: Dockerfile from file
Description: Create Dockerfile from a file (R script, R Markdown document)
Binding: fromFile_addin
Interactive: true

Name: From list of expressions
Description: Create dockerfile from a list of expressions
Binding: fromexpressions_addin
Name: Dockerfile from expressions
Description: Create Dockerfile from a list of expressions
Binding: fromExpressions_addin
Interactive: true

Name: From workspace directory
Description: Create dockerfile from a workspace directory
Binding: workspaceDirectory_addin
Name: Dockerfile from workspace
Description: Create Dockerfile from a workspace directory
Binding: fromWorkspaceDirectory_addin
Interactive: true
18 changes: 18 additions & 0 deletions inst/scripts/common.R
@@ -0,0 +1,18 @@
# Common objects for Addin script files
file_dialog_volumes <- c("Working directory" = getwd(), "Home directory" = "~")

save_button <- function() {
shinyFiles::shinySaveButton(id = "save",
label = "Save as...",
title = "Save file as ..."
# , filetype = list(dockerfile = "Dockerfile")
)
}

# Output docker instructions to console
print_docker_instructions <- function(file) {
cat("You can now use the Docker CLI to build the Dockerfile and run the image:",
"\n>> cd ", dirname(file),
"\n>> docker build . -t [tag] -f", basename(file),
"\n>> docker run -t [tag]")
}
74 changes: 34 additions & 40 deletions inst/scripts/package-expressions.R
@@ -1,66 +1,60 @@
## GUI - package_expressions
expressionsAddIn <- function(){
fromExpressions <- function(){

ui <- miniUI::miniPage(
miniUI::gadgetTitleBar("Dockerfile creation"),
miniUI::miniContentPanel(
shiny::p(shiny::strong("Create a .dockerfile file from a list of expressions")),
shiny::p(shiny::strong("Create a Dockerfile from a list of expressions")),
shiny::p("Input a vector of expressions. For example;"),
shiny::p(shiny::code(
"c( expression(library(sp)),
expression(data(meuse)),
expression(data(meuse)),
expression(mean(meuse[[\"zinc\"]])) )")),
shiny::p("For more information see the getting
started page at https://o2r.info/containerit/articles/containerit.html."),
shiny::textAreaInput("expressions", "List of Expressions", "", height="240px", width="500px"),
shiny::p("For more information see documentation at https://o2r.info/containerit/articles/containerit.html."),
shiny::textAreaInput(inputId = "expressions",
label = "List of Expressions",
value = "",
height = "240px",
width = "500px"),
shiny::fillRow(
shiny::textInput("text",NULL,
value = paste0(getwd(),"/dockerfile.dockerfile")),
shinyFiles::shinySaveButton("save", "Save as...", "Save file as ...",
filetype=list(dockerfile="dockerfile")),
height = '50px'
)
shiny::textInput(inputId = "text",
label = NULL,
value = file.path(getwd(), "Dockerfile")),
save_button(),
height = "50px"
)
)



)

server <- function(input, output, session){
shiny::observeEvent(input$save,{
volumes <- c("Working directory"=getwd(),"Home Directory"="~")
shinyFiles::shinyFileSave(input, "save", roots=volumes, session=session)
fileinfo <- shinyFiles::parseSavePath(volumes, input$save)
if(length(fileinfo$datapath)!=0) {
shinyFiles::shinyFileSave(input, "save",
roots = file_dialog_volumes,
session = session)
fileinfo <- shinyFiles::parseSavePath(roots = file_dialog_volumes,
selection = input$save)
if (length(fileinfo$datapath) != 0) {
shiny::updateTextInput(session, "text", value = fileinfo$datapath)
}
})

shiny::observeEvent(input$done, {

# Here is where your Shiny application might now go an affect the
# contents of a document open in RStudio, using the `rstudioapi` package.
#
# At the end, your application should call 'stopApp()' here, to ensure that
# the gadget is closed after 'done' is clicked.

# Exit app to ensure that the gadget is closed after 'done' is clicked.
shiny::stopApp()

# Create the session object
session <- containerit::clean_session(input$expressions, echo = TRUE)
# Create docker file
dockerfile_object <- containerit::dockerfile(from=session)
# Output to desired path

# Create docker file and write to desired path
dockerfile_object <- containerit::dockerfile(from = session)
containerit::write(dockerfile_object, file = input$text)
# Output docker instructions
cat(paste0("\nInstructions to run docker container from command line:\n
>> docker build . -t [tag] -f ", basename(fn_args[['output_filename']])), "\n
>> docker run -t [tag]")
# Exit app
shiny::stopApp()

print_docker_instructions(input$text)
})

}


viewer <- shiny::dialogViewer(dialogName = "containerit")
shiny::runGadget(ui, server, viewer = viewer)
shiny::runGadget(app = ui, server = server, viewer = viewer)
}

expressionsAddIn()
fromExpressions()
85 changes: 40 additions & 45 deletions inst/scripts/package-interactive-session.R
@@ -1,57 +1,52 @@
## GUI - package_interactive_session
interactiveAddIn <- function(){
fromSession <- function(){

ui <- miniUI::miniPage(
miniUI::gadgetTitleBar("Dockerfile creation"),
miniUI::miniContentPanel(
shiny::fillRow(
shiny::textInput("text",NULL,
value = paste0(getwd(),"/dockerfile.dockerfile")),
shinyFiles::shinySaveButton("save", "Select file", "Save file as ...",
filetype=list(dockerfile="dockerfile")),
height = '50px'
),
shiny::checkboxInput("saveimage", "Save global R objects to dockerfile", TRUE)
)
shiny::textInput(inputId = "text",
label = NULL,
value = file.path(getwd(), "Dockerfile")),
save_button(),
height = "50px"
),
shiny::checkboxInput("saveimage", "Save global R objects to Dockerfile", TRUE)
)



)

server <- function(input, output, session){
shiny::observeEvent(input$save,{
volumes <- c("Working directory"=getwd(),"Home Directory"="~")
shinyFiles::shinyFileSave(input, "save", roots=volumes, session=session)
fileinfo <- shinyFiles::parseSavePath(volumes, input$save)
if(length(fileinfo$datapath)!=0) {
shiny::updateTextInput(session, "text", value = fileinfo$datapath)
}
})
shiny::observeEvent(input$done, {

# Here is where your Shiny application might now go an affect the
# contents of a document open in RStudio, using the `rstudioapi` package.
#
# At the end, your application should call 'stopApp()' here, to ensure that
# the gadget is closed after 'done' is clicked.

# Exit app first
shiny::stopApp()
# Create docker file
dockerfile_object <- containerit::dockerfile(save_image=input$saveimage)
# Output to desired path
containerit::write(dockerfile_object, file = input$text)

# Output docker instructions
cat(paste0("\nInstructions to run docker container from command line:\n
>> docker build . -t [tag] -f ", basename(fn_args[['output_filename']])), "\n
>> docker run -t [tag]")
})

shiny::observeEvent(eventExpr = input$save,
handlerExpr = {
volumes <- c("Working directory" = getwd(), "Home directory" = "~")
shinyFiles::shinyFileSave(input = input,
id = "save",
roots = volumes,
session = session)
fileinfo <- shinyFiles::parseSavePath(roots = volumes,
selection = input$save)
if (length(fileinfo$datapath) != 0) {
shiny::updateTextInput(session = session,
inputId = "text",
value = fileinfo$datapath)
}
})

shiny::observeEvent(eventExpr = input$done,
handlerExpr = {
# Exit app to ensure that the gadget is closed after 'done' is clicked.
shiny::stopApp()

# Create Dockerfile and write to desired path
dockerfile_object <- containerit::dockerfile(save_image = input$saveimage)
containerit::write(dockerfile_object, file = input$text)

print_docker_instructions(input$text)
})
}


viewer <- shiny::dialogViewer(dialogName = "containerit")
shiny::runGadget(ui, server, viewer = viewer)
shiny::runGadget(app = ui, server = server, viewer = viewer)
}

interactiveAddIn()
fromSession()

0 comments on commit 5d54092

Please sign in to comment.