-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add interactive widget for specifying names when bursting pipes (close …
…#5)
- Loading branch information
1 parent
4ef5ecd
commit a9ca513
Showing
15 changed files
with
173 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
Type: Package | ||
Package: pipecleaner | ||
Title: Debug magrittr Pipelines | ||
Title: Debug and Refactor magrittr Pipelines | ||
Version: 0.0.2.9000 | ||
Authors@R: person("Edward", "Visel", email = "[email protected]", | ||
role = c("aut", "cre")) | ||
Description: Run a magrittr pipeline element-by-element in the debugging browser. | ||
Description: Tools for refactoring and debugging magrittr pipelines. | ||
License: GPL-3 | ||
URL: https://github.com/alistaire47/pipecleaner | ||
BugReports: https://github.com/alistaire47/pipecleaner/issues | ||
Depends: | ||
R (>= 3.2) | ||
Imports: | ||
miniUI, | ||
rlang, | ||
rstudioapi | ||
rstudioapi, | ||
shiny, | ||
shinyAce | ||
Suggests: | ||
covr, | ||
magrittr, | ||
|
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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Shiny `burst_pipes` RStudio add-in | ||
burst_pipes_addin <- function() { | ||
pipeline_text <- rstudioapi::getSourceEditorContext()$selection[[1]]$text | ||
if (pipeline_text == "") { | ||
initial_tab <- "Change pipeline" | ||
} else { | ||
pipeline_init <- rlang::parse_expr(pipeline_text) | ||
n_lines <- length(split_pipeline(pipeline_init, parse = FALSE)) - 1 | ||
initial_tab <- "Set names" | ||
} | ||
|
||
ui <- miniUI::miniPage( | ||
shiny::div(style = "display:none;", shinyAce::aceEditor("invisible")), | ||
miniUI::gadgetTitleBar( | ||
"Burst pipes", | ||
right = miniUI::miniTitleBarButton("done", "Replace code", primary = TRUE) | ||
), | ||
miniUI::miniTabstripPanel( | ||
id = "tab", | ||
selected = initial_tab, | ||
miniUI::miniTabPanel( | ||
"Change pipeline", value = "Change pipeline", | ||
icon = shiny::icon("bars"), | ||
miniUI::miniContentPanel(shinyAce::aceEditor( | ||
"pipeline_code", | ||
value = pipeline_text, | ||
mode = "r", | ||
theme = "tomorrow", | ||
wordWrap = TRUE, | ||
autoComplete = "enabled" | ||
)) | ||
), | ||
miniUI::miniTabPanel( | ||
"Set names", value = "Set names", | ||
icon = shiny::icon("list-ul"), | ||
miniUI::miniContentPanel( | ||
shiny::fillRow( | ||
flex = c(1, 2), | ||
shiny::code( | ||
style = "padding: 0px;", | ||
shiny::uiOutput("text_boxes") | ||
), | ||
shinyAce::aceEditor( | ||
"code", | ||
value = utils::capture.output( | ||
burst_pipes(pipeline_init, parse = FALSE) | ||
), | ||
mode = "r", | ||
theme = "tomorrow", | ||
wordWrap = TRUE, | ||
autoComplete = "enabled" | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
server <- function(input, output, session) { | ||
|
||
pipeline <- shiny::reactive({ | ||
tryCatch( | ||
rlang::parse_expr(paste(input$pipeline_code, collapse = " ")), | ||
error = function(e) structure( | ||
quote("Invalid input" %>% print()), | ||
invalid = TRUE | ||
) | ||
) | ||
}) | ||
|
||
n_lines <- shiny::reactive({ | ||
length(split_pipeline(pipeline(), parse = FALSE)) - 1 | ||
}) | ||
|
||
shiny::observe({ | ||
output$text_boxes <- shiny::renderUI(lapply(seq(n_lines()), function(i){ | ||
shiny::textInput( | ||
inputId = paste0("name", i), | ||
label = if (i == 1) "Names:" else NULL, | ||
value = paste0("dot", i), | ||
width = "90%" | ||
) | ||
})) | ||
}) | ||
|
||
line_names <- shiny::reactive({ | ||
names <- vapply( | ||
grep("^name\\d+$", names(input), value = TRUE), | ||
function(n) input[[n]], | ||
character(1) | ||
) | ||
names[names == ""] <- paste0("dot", seq(n_lines))[names == ""] | ||
names | ||
}) | ||
|
||
shiny::observe({ | ||
if (input$tab == "Set names") { | ||
# ensure #names == #calls | ||
dot_names <- paste0('dot', seq(n_lines())) | ||
i <- seq(min(n_lines(), length(line_names()))) | ||
dot_names[i] <- line_names()[i] | ||
|
||
if (isTRUE(attr(pipeline(), "invalid"))) { | ||
value <- "Error: Invalid input" | ||
} else { | ||
value <- paste(utils::capture.output( | ||
burst_pipes(pipeline(), dot_names, parse = FALSE) | ||
), collapse = "\n") | ||
} | ||
|
||
shinyAce::updateAceEditor(session, "code", value = value) | ||
} | ||
}) | ||
|
||
# replace text and close | ||
shiny::observeEvent(input$done, { | ||
|
||
rstudioapi::modifyRange( | ||
rstudioapi::getSourceEditorContext()$selection[[1]]$range, | ||
input$code | ||
) | ||
shiny::stopApp() | ||
}) | ||
} | ||
|
||
shiny::runGadget(ui, server) | ||
|
||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.