forked from o2r-project/containerit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
207 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Oops, something went wrong.