Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aceAutocomplete not working when invoked within module #49

Closed
GregorDeCillia opened this issue Oct 16, 2017 · 7 comments
Closed

aceAutocomplete not working when invoked within module #49

GregorDeCillia opened this issue Oct 16, 2017 · 7 comments

Comments

@GregorDeCillia
Copy link
Contributor

I read about some previous bug with shiny modules and I am afraid I found another one. When I call aceAutocomplete within a shiny module, autoComplete does not get enabled. Interestingly enough, everything works if I call aceAutocomplete in the global server - even if the targeted input id is part of a module. Here is a minimal example.

Editor <- function(input, output, session){
  ns = session$ns
  shinyAce::aceAutocomplete(ns("editor"))
  shinyAce::aceAutocomplete("editor")
}

EditorUI <- function(id){
  ns = NS(id)
  shinyAce::aceEditor(
    ns("editor"),
    "default",
    autoComplete = "live"
  )
}

my_id = "editor_id"
#my_id = NULL

shinyApp(
  EditorUI(my_id),
  function(input, output, session){
    callModule(Editor, my_id)
    #shinyAce::aceAutocomplete(NS(my_id, "editor"))
  }
)

If either of the commented lines get removed, autocomplete is working properly. In the first case, the module basically writes its outputs in the main session since NS(NULL) is the identity function. In the second case, aceAutocomplete gets invoked with the same id but a different session argument.

I found that passing session to the module as a parameter fixes the problem, but I really don't like this approach, since my modules are nested.

domain <- session
callModule(Editor, my_id, domain)  # use domain in aceAutocomplete 
@vnijs
Copy link
Collaborator

vnijs commented Apr 2, 2018

I don't use modules much and there is a pretty major new release of Shiny coming up. If the update to Shiny doesn't address your issue perhaps you could provide a PR for shinyAce?

@vnijs vnijs closed this as completed Apr 2, 2018
@GregorDeCillia
Copy link
Contributor Author

Thanks for your reply. I just tried my example above with the newest version of shiny to no avail.

My guess is that the namespaces are not working properly since there is some id of the form

shinyAce_editorId_hint

responsible for the completions. However, shiny modules only allow suffixes for ids, no prefixes. I'll take a look and try to submit a PR.

@vnijs
Copy link
Collaborator

vnijs commented Apr 6, 2018

@GregorDeCillia Could you check if the current version on GitHub (0.3.01) works as expect in your setting? Thanks for your help!

@vnijs vnijs reopened this Apr 6, 2018
@GregorDeCillia
Copy link
Contributor Author

GregorDeCillia commented Apr 7, 2018

Thank you for the quick merge!

It almost works. In R/aceAutocomplete.R you just need to replace

comps <- list(
  id = inputId,
  codeCompletions = jsonlite::toJSON(codeCompletions, auto_unbox = TRUE)
)

with

comps <- list(
  id = session$ns(inputId),
  codeCompletions = jsonlite::toJSON(codeCompletions, auto_unbox = TRUE)
)

as I did in my PR. These changes where reverted in the subsequent merge 6cab775.

I tested this now with my actual project, which includes nested modules, dnymaic updates of contents and styles, renderUI and much more. So I can confidently say this solution works.

@vnijs
Copy link
Collaborator

vnijs commented Apr 7, 2018

Thanks for checking @GregorDeCillia. The current version on GitHub should work but please do check. FYI I also updated credits in the NEWS.md and README.md files.

@GregorDeCillia
Copy link
Contributor Author

GregorDeCillia commented Apr 7, 2018

I can confirm that the current version on GitHub does work with my project. Thanks for mentioning me as a contributor.

@vnijs
Copy link
Collaborator

vnijs commented Apr 7, 2018

Thanks @GregorDeCillia. Closing issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants