Title: | Ace Editor Bindings for Shiny |
---|---|
Description: | Ace editor bindings to enable a rich text editing environment within Shiny. |
Authors: | Vincent Nijs [aut, cre], Forest Fang [aut], Trestle Technology, LLC [aut], Jeff Allen [aut], Institut de Radioprotection et de Surete Nucleaire [cph], Ajax.org B.V. [ctb, cph] (Ace) |
Maintainer: | Vincent Nijs <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.4.3 |
Built: | 2024-11-19 06:11:39 UTC |
Source: | https://github.com/trestletech/shinyace |
Regular expression for matching the function name in a completion line in the middle of a function call
.fname_regex
.fname_regex
An object of class character
of length 1.
Get namespace to get access to unexported functions, namely RdTags
.tools
.tools
An object of class environment
of length 792.
Get namespace to get access to unexported functions, namely .getHelpFile .assignLinebuffer .assignEnd .guessTokenFromLine .completeToken
.utils
.utils
An object of class environment
of length 576.
This function dynamically evaluate R for syntax errors using the
parse
function.
aceAnnotate(inputId, session = shiny::getDefaultReactiveDomain())
aceAnnotate(inputId, session = shiny::getDefaultReactiveDomain())
inputId |
The id of the input object |
session |
The |
You can implement your own code completer by observing modification events to
input$<editorId>_shinyAce_annotationTrigger
where <editorId> is the
aceEditor
id. This input is only used for triggering completion and
will contain a random number. However, you can access
session$input[[inputId]]
to get the input text for parsing.
An observer reference class object that is responsible for offering
code annotations. See observeEvent
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 annotations endpoint containing
a json list of annotation metadata objects. The json list should have
a structure akin to:
[ { row: <int: row of annotation reference>, col: <int: column of annotation reference>, type: <str: "error", "alert" or "flash">, html: <str: html of annotation hover div, used by default over text>, text: <num: text of annotation hover div>, } ]
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())
aceAutocomplete(inputId, session = shiny::getDefaultReactiveDomain())
inputId |
The id of the input object |
session |
The |
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
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>, } ]
Render an Ace editor on an application page.
aceEditor( outputId, value, mode, theme, vimKeyBinding = FALSE, readOnly = FALSE, height = "400px", fontSize = 12, debounce = 1000, wordWrap = FALSE, showLineNumbers = TRUE, highlightActiveLine = TRUE, selectionId = NULL, cursorId = NULL, hotkeys = NULL, code_hotkeys = NULL, autoComplete = c("disabled", "enabled", "live"), autoCompleters = c("snippet", "text", "keyword"), autoCompleteList = NULL, tabSize = 4, useSoftTabs = TRUE, showInvisibles = FALSE, setBehavioursEnabled = TRUE, showPrintMargin = TRUE, autoScrollEditorIntoView = FALSE, maxLines = NULL, minLines = NULL, placeholder = NULL )
aceEditor( outputId, value, mode, theme, vimKeyBinding = FALSE, readOnly = FALSE, height = "400px", fontSize = 12, debounce = 1000, wordWrap = FALSE, showLineNumbers = TRUE, highlightActiveLine = TRUE, selectionId = NULL, cursorId = NULL, hotkeys = NULL, code_hotkeys = NULL, autoComplete = c("disabled", "enabled", "live"), autoCompleters = c("snippet", "text", "keyword"), autoCompleteList = NULL, tabSize = 4, useSoftTabs = TRUE, showInvisibles = FALSE, setBehavioursEnabled = TRUE, showPrintMargin = TRUE, autoScrollEditorIntoView = FALSE, maxLines = NULL, minLines = NULL, placeholder = NULL )
outputId |
The ID associated with this element |
value |
The initial text to be contained in the editor. |
mode |
The Ace |
theme |
The Ace |
vimKeyBinding |
If set to |
readOnly |
If set to |
height |
A number (which will be interpreted as a number of pixels) or
any valid CSS dimension (such as " |
fontSize |
Defines the font size (in px) used in the editor and should be an integer. The default is 12. |
debounce |
The number of milliseconds to debounce the input. This will cause the client to withhold update notifications until the user has stopped typing for this amount of time. If 0, the server will be notified of every keystroke as it happens. |
wordWrap |
If set to |
showLineNumbers |
If set to |
highlightActiveLine |
If set to |
selectionId |
The ID associated with a change of selected text |
cursorId |
The ID associated with a cursor change. |
hotkeys |
A list whose names are ID names and whose elements are the shortcuts of keys. Shortcuts can either be a simple string or a list with elements 'win' and 'mac' that that specifies different shortcuts for win and mac (see example 05). |
code_hotkeys |
A nested list. The first element indicates the code type (e.g., "r")
The second element is a list whose names are ID names and whose elements are the
shortcuts of keys (see |
autoComplete |
Enable/Disable auto code completion. Must be one of the following:
By default, only local completer is used where all aforementioned code pieces
will be considered as candidates. Use |
autoCompleters |
Character vector of completers to enable. If set to |
autoCompleteList |
A named list that contains static code completions
candidates. This can be especially useful for Non-Standard Evaluation (NSE)
functions such as those in |
tabSize |
Set tab size. Default value is 4 |
useSoftTabs |
Replace tabs by spaces. Default value is TRUE |
showInvisibles |
Show invisible characters (e.g., spaces, tabs, newline characters). Default value is FALSE |
setBehavioursEnabled |
Determines if the auto-pairing of special characters, like quotation marks, parenthesis, or brackets should be enabled. Default value is TRUE. |
showPrintMargin |
Show print margin. Default value is True |
autoScrollEditorIntoView |
If TRUE, expands the size of the editor window as new lines are added |
maxLines |
Maximum number of lines the editor window will expand to when autoScrollEditorIntoView is TRUE |
minLines |
Minimum number of lines in the editor window when autoScrollEditorIntoView is TRUE |
placeholder |
A string to use a placeholder when the editor has no content |
Jeff Allen [email protected]
## Not run: aceEditor( outputId = "myEditor", value = "Initial text for editor here", mode = "r", theme = "ambiance" ) aceEditor( outputId = "myCodeEditor", value = "# Enter code", mode = "r", hotkeys = list( helpKey = "F1", runKey = list( win = "Ctrl-R|Ctrl-Shift-Enter", mac = "CMD-ENTER|CMD-SHIFT-ENTER" ) ), wordWrap = TRUE, debounce = 10 ) aceEditor( outputId = "mySmartEditor", value = "plot(wt ~ mpg, data = mtcars)", mode = "r", autoComplete = "live", autoCompleteList = list(mtcars = colnames(mtcars)) ) ## End(Not run)
## Not run: aceEditor( outputId = "myEditor", value = "Initial text for editor here", mode = "r", theme = "ambiance" ) aceEditor( outputId = "myCodeEditor", value = "# Enter code", mode = "r", hotkeys = list( helpKey = "F1", runKey = list( win = "Ctrl-R|Ctrl-Shift-Enter", mac = "CMD-ENTER|CMD-SHIFT-ENTER" ) ), wordWrap = TRUE, debounce = 10 ) aceEditor( outputId = "mySmartEditor", value = "plot(wt ~ mpg, data = mtcars)", mode = "r", autoComplete = "live", autoCompleteList = list(mtcars = colnames(mtcars)) ) ## End(Not run)
This function uses the completion item object to retrieve tooltip information
by parsing R help
documentation and rendering to html.
aceTooltip(inputId, session = shiny::getDefaultReactiveDomain())
aceTooltip(inputId, session = shiny::getDefaultReactiveDomain())
inputId |
The id of the input object |
session |
The |
You can implement your own tooltips by observing modification events to
input$<editorId>_shinyAce_tooltipItem
where <editorId> is the
aceEditor
id. This input contains the object passed to codeCompletion
for this item. See the help for aceAutocomplete
for details on
the fields of the completion item object.
An observer reference class object that is responsible for offering
completion tooltips. 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 docTooltip endpoint containing a
json list of completion item metadata objects. The json list should have a
structure akin to one of:
A text object
<str: text to display for tooltip>
An object containing a docHTML
property
{ docHTML: <str: html to display for tooltip div, used if available>, }
An object containing a docText
property
{ docText: <str: text to display for tooltip div> }
Build the fields used to make an html tooltip
build_tooltip_fields(v)
build_tooltip_fields(v)
v |
Autocomplete metadata values used for building tooltip info |
a list with html-formatted character values "title" and "body
Retrieve argument documentation from help document
get_arg_help(..., args = character())
get_arg_help(..., args = character())
... |
arguments passed to get_help_file |
args |
function arguments names to get documentation for |
A character vector of help
shinyAce:::get_arg_help("match", package = "base", args = c("table", "nomatch"))
shinyAce:::get_arg_help("match", package = "base", args = c("table", "nomatch"))
Retrieve description section from help document
get_desc_help(...)
get_desc_help(...)
... |
arguments passed to get_help_file |
a character value representing the description section of a help document, rendered as HTML
shinyAce:::get_desc_help("match", package = "base")
shinyAce:::get_desc_help("match", package = "base")
Safely return NULL if an error is encountered.
get_help_file(...)
get_help_file(...)
... |
arguments passed to |
the Rd object returned from utils:::getHelpFile
Retrieve usage section from help document
get_usage_help(...)
get_usage_help(...)
... |
arguments passed to get_help_file |
a character value representing the usage section of a help document, rendered as HTML
shinyAce:::get_usage_help("match", package = "base")
shinyAce:::get_usage_help("match", package = "base")
Gets all of the available modes
available in the installed version
of shinyAce. Modes are often the programming or markup language which will
be used in the editor and determine things like syntax highlighting and
code folding.
getAceModes()
getAceModes()
Jeff Allen [email protected]
Gets all of the available themes
available in the installed version
of shinyAce. Themes determine the styling and colors used in the editor.
getAceThemes()
getAceThemes()
Jeff Allen [email protected]
Check if vector is empty
is.empty(x)
is.empty(x)
x |
vector |
is.empty(NULL) is.empty(NA) is.empty(c()) is.empty("") is.empty(" ") is.empty(c(" ", " ")) is.empty(list()) is.empty(list(a = "", b = ""))
is.empty(NULL) is.empty(NA) is.empty(c()) is.empty("") is.empty(" ") is.empty(c(" ", " ")) is.empty(list()) is.empty(list(a = "", b = ""))
Character value to use for object meta field
meta_obj()
meta_obj()
Character value to use for package meta field
meta_pkg()
meta_pkg()
R completions when cursor is within a function call
r_completions_function_call_metadata(fname, completions)
r_completions_function_call_metadata(fname, completions)
fname |
the function name for which the function call specific completion metadata should be constructed |
completions |
a character vector of completions. These will serve as the foundation for building added R-specific metadata |
R completions for general case
r_completions_general_metadata(completions)
r_completions_general_metadata(completions)
completions |
a character vector of completions. These will serve as the foundation for building added R-specific metadata |
Return completions for a given line of text
r_completions_metadata(line)
r_completions_metadata(line)
line |
the text up until the cursor in the line for autocompletion |
Convert an Rd object to HTML
rd_2_html(...)
rd_2_html(...)
... |
additional parameters to pass to |
a character value of Rd content rendered as HTML
Retrieve regular expression named capture groups as a list
re_capture(x, re, ...)
re_capture(x, re, ...)
x |
a character string to capture from |
re |
the regular expression to use |
... |
additional arguments passed to |
a named list of matches
shinyAce:::re_capture("ak09j b", "(?<num>\\d+)(?<alpha>[a-zA-Z]+)", perl = TRUE)
shinyAce:::re_capture("ak09j b", "(?<num>\\d+)(?<alpha>[a-zA-Z]+)", perl = TRUE)
Function for handling optional debugging messages
shinyAce_debug(...)
shinyAce_debug(...)
... |
zero or more objects which can be coerced to character
(and which are pasted together with no separator) or (for
|
shinyAce.debug
Logical value to enable or disable debugging messages
being printed to console. default behavior equivalent to FALSE
.
A helper for formatting a tooltip entry
tooltip_html(title = "", body = "")
tooltip_html(title = "", body = "")
title |
a character value to use as the title |
body |
an html block to embed as the body of the tooltip |
Update the styling or mode of an aceEditor component.
updateAceEditor( session, editorId, value, theme, readOnly, mode, fontSize, showLineNumbers, wordWrap, useSoftTabs, tabSize, showInvisibles, showPrintMargin, border = c("normal", "alert", "flash"), autoComplete = c("disabled", "enabled", "live"), autoCompleters = c("snippet", "text", "keyword", "static", "rlang"), autoCompleteList = NULL )
updateAceEditor( session, editorId, value, theme, readOnly, mode, fontSize, showLineNumbers, wordWrap, useSoftTabs, tabSize, showInvisibles, showPrintMargin, border = c("normal", "alert", "flash"), autoComplete = c("disabled", "enabled", "live"), autoCompleters = c("snippet", "text", "keyword", "static", "rlang"), autoCompleteList = NULL )
session |
The Shiny session to whom the editor belongs |
editorId |
The ID associated with this element |
value |
The initial text to be contained in the editor. |
theme |
The Ace |
readOnly |
If set to |
mode |
The Ace |
fontSize |
If set, will update the font size (in px) used in the editor. Should be an integer. |
showLineNumbers |
If set to |
wordWrap |
If set to |
useSoftTabs |
Replace tabs by spaces. Default value is TRUE |
tabSize |
Set tab size. Default value is 4 |
showInvisibles |
Show invisible characters (e.g., spaces, tabs, newline characters). Default value is FALSE |
showPrintMargin |
Show print margin. Default value is True |
border |
Set the |
autoComplete |
Enable/Disable code completion. See |
autoCompleters |
Character vector of completers to enable. If set to |
autoCompleteList |
If set to |
Jeff Allen [email protected]
## Not run: shinyServer(function(input, output, session) { observe({ updateAceEditor(session, "myEditor", "Updated text for editor here", mode = "r", theme = "ambiance") }) } ## End(Not run)
## Not run: shinyServer(function(input, output, session) { observe({ updateAceEditor(session, "myEditor", "Updated text for editor here", mode = "r", theme = "ambiance") }) } ## End(Not run)