This function dynamically auto complete R code pieces using built-in functions utils:::.assignLinebuffer, utils:::.assignEnd, utils:::.guessTokenFromLine and utils:::.completeToken.

aceAutocomplete(inputId, session = shiny::getDefaultReactiveDomain())

Arguments

inputId

The id of the input object

session

The session object passed to function given to shinyServer

Value

An observer reference class object that is responsible for offering code completion. See observe for more details. You can use suspend or destroy to pause to stop dynamic code completion. The observer reference object will send a custom shiny message using session$sendCustomMessage to the codeCompletions endpoint containing a json list of completion item metadata objects. The json list should have a structure akin to:


  [
    {
       value:        <str: value to be inserted upon completion (e.g. "print()")>,
       caption:      <str: value to be displayed (e.g. "print() # prints text")>,
       score:        <num: score to pass to ace editor for sorting>,
       meta:         <str: meta text on right of completion>
       r_symbol:     <str: symbol name of completion item>,
       r_envir_name: <str: name of the environment from which the symbol is referenced>,
       r_help_type:  <str: a datatype for dispatching help documentation function>,
       completer:    <str: used for dispatching default insertMatch functions>,
    }
  ]
  

Details

You can implement your own code completer by listening to input$<editorId>_shinyAce_hint where <editorId> is the aceEditor id. The input contains

  • linebuffer: Code/Text at current editing line

  • cursorPosition: Current cursor position at this line