Skip to content

Commit

Permalink
Merge pull request #52 from saurfang/autocomplete-list
Browse files Browse the repository at this point in the history
[Completion] Fix AutoCompleteList in Constructor
  • Loading branch information
vnijs authored Apr 4, 2018
2 parents 3f8a12f + d04ae51 commit 89037d6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ License: MIT + file LICENSE
Depends:
R (>= 3.4.0)
Imports:
shiny (>= 1.0.5)
shiny (>= 1.0.5),
jsonlite
Suggests:
testthat (>= 2.0.0),
dplyr (>= 0.7.4)
Expand Down
2 changes: 1 addition & 1 deletion R/ace-editor.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ aceEditor <- function(
id = outputId,
class = "shiny-ace",
style = paste("height:", validateCssUnit(height)),
`data-autoCompleteList` = autoCompleteList
`data-auto-complete-list` = jsonlite::toJSON(autoCompleteList)
),
tags$script(type = "text/javascript", HTML(js))
)
Expand Down
10 changes: 5 additions & 5 deletions inst/examples/06-autocomplete/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ shinyServer(function(input, output, session) {

### Auto Compeltion ####
observe({
autoComplete <- if(input$enableAutocomplete) {
if(input$enableLiveCompletion) "live" else "enabled"
autoComplete <- if (input$enableAutocomplete) {
if (input$enableLiveCompletion) "live" else "enabled"
} else {
"disabled"
}
Expand All @@ -27,15 +27,15 @@ shinyServer(function(input, output, session) {

#Update static autocomplete list according to dataset
observe({
comps <- if(input$enableNameCompletion) structure(list(colnames(dataset())), names = input$dataset)
comps <- if (input$enableNameCompletion) structure(list(colnames(dataset())), names = input$dataset)
updateAceEditor(session, "mutate", autoCompleteList = comps)
})

#Enable/Disable R code completion
mutateOb <- aceAutocomplete("mutate")
plotOb <- aceAutocomplete("plot")
observe({
if(input$enableRCompletion) {
if (input$enableRCompletion) {
mutateOb$resume()
plotOb$resume()
} else {
Expand All @@ -54,7 +54,7 @@ shinyServer(function(input, output, session) {
code1 <- gsub("\\s+$", "", isolate(input$mutate))
code2 <- gsub("\\s+$", "", isolate(input$plot))

eval(parse(text = isolate(paste(input$dataset, "%>%", code1, "%>% function(data) {", code2, "}"))))
eval(parse(text = isolate(paste(input$dataset, "%>%", code1, "%>% {", code2, "}"))))
}, error = function(ex) {
output$error <- renderPrint(ex)

Expand Down
6 changes: 3 additions & 3 deletions inst/examples/06-autocomplete/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ shinyUI(fluidPage(
Use Ctrl+Space for code completion when enabled."),
radioButtons("dataset", "Dataset: ", c("mtcars", "airquality"), inline = TRUE),
tags$pre(" %>%"),
aceEditor("mutate", mode="r", value="select(wt, mpg) \n", height = "50px"),
tags$pre(" %>% function(data) {"),
aceEditor("plot", mode="r", value="plot(data) \n", height = "50px"),
aceEditor("mutate", mode = "r", value = "select(wt, mpg) \n", height = "50px"),
tags$pre(" %>% {"),
aceEditor("plot", mode = "r", value = "plot(.) \n", height = "50px"),
tags$pre(" }"),
div(actionButton("eval", "Eval"), class = "pull-right"),
br(), #pad the above pull-right
Expand Down
4 changes: 2 additions & 2 deletions inst/www/shinyAce.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var langTools = ace.require("ace/ext/language_tools");
var staticCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
//if (prefix.length === 0) { callback(null, []); return }
var comps = $('#' + editor.container.id).data('autoCompleteList');
var comps = $('#' + editor.container.id).data('auto-complete-list');
if(comps){
var words = [];

Expand Down Expand Up @@ -134,7 +134,7 @@ Shiny.addCustomMessageHandler('shinyAce', function(data) {
}

if (data.hasOwnProperty('autoCompleteList')) {
$el.data('autoCompleteList', data.autoCompleteList);
$el.data('auto-complete-list', data.autoCompleteList);
}

if (data.codeCompletions) {
Expand Down

0 comments on commit 89037d6

Please sign in to comment.