Description Details Active bindings Methods Examples
Highlight text in shiny.
Initialise a marker object to point at a CSS
selector
then use methods to mark
or
unmark
text.
session
Get or set the session, if NULL returns the previously assigned reactive context.
name
Set the name to identify the marker internally. This is read-only.
new()
marker$new(selector, session = NULL, name = NULL)
selector
A valid CSS selector, e.g.: #id
,
.class
, or div
.
session
A valid shiny session, if NULL
(default)
then the function attempts to get the current reacive domain.
name
A name, useful to distinguish between markers. If
NULL
a random name is generated.
Initialise a marker with new
method.
library(shiny) # load a paragraph data(lorem, package = "marker") ui <- fluidPage( useMarker(), p(id = "text-to-mark", lorem), textInput("mark", "Text to mark") ) server <- function(input, output){ my_marker <- marker$new("#text-to-mark") observeEvent(input$mark, { my_marker$ unmark()$ # unmark previously marked text mark(input$mark) # mark what is searched }) } if(interactive()) shinyApp(ui, server)
mark()
marker$mark(keywords, ..., send_marked = FALSE, delay = 0)
keywords
A vector or character string of keywords to highlight.
...
Options passed to JavaScript, see the official documentation under "mark" for the full list.
send_marked
Whether to send the number of highlighted
keywords to the R server. These can then be accessed with
the get_marked
method. Note that this overwrites the
done
options passed to the three dot construct.
delay
Delay in milliseconds before highlighting text.
A method to highlight custom search terms.
library(shiny) # load a paragraph data(lorem, package = "marker") ui <- fluidPage( useMarker(), p(id = "text-to-mark", lorem), actionButton("mark", "Mark lorem") ) server <- function(input, output){ my_marker <- marker$new("#text-to-mark") observeEvent(input$mark, { my_marker$ unmark()$ # unmark previously marked text mark("lorem") # mark what is searched }) } if(interactive()) shinyApp(ui, server)
unmark()
marker$unmark(...)
...
Options passed to JavaScript, see the official documentation under "unmark" for the full list.
A method to remove highlights created by mark.js.
mark_regex()
marker$mark_regex(regex, ..., send_marked = FALSE, delay = 0)
regex
A valid regular expression.
...
Options passed to JavaScript, see the official documentation under "markRegExp" for the full list.
send_marked
Whether to send the number of highlighted
keywords to the R server. These can then be accessed with
the get_marked
method. Note that this overwrites the
done
options passed to the three dot construct.
delay
Delay in milliseconds before highlighting text.
A method to highlight custom regular expressions.
library(shiny) # load a paragraph data(lorem, package = "marker") ui <- fluidPage( useMarker(), p(id = "text-to-mark", lorem), actionButton("mark", "Mark") ) server <- function(input, output){ my_marker <- marker$new("#text-to-mark") observeEvent(input$mark, { my_marker$ unmark()$ # unmark previously marked text mark_regex('[a-z]') # mark what is searched }) } if(interactive()) shinyApp(ui, server)
mark_ranges()
marker$mark_ranges(ranges, ..., send_marked = FALSE)
ranges
A list of ranges list(list(start = 1, length = 3), list(start = 5, length = 3))
.
...
Options passed to JavaScript, see the official documentation under "markRanges" for the full list.
send_marked
Whether to send the number of highlighted
keywords to the R server. These can then be accessed with
the get_marked
method. Note that this overwrites the
done
options passed to the three dot construct.
A method to mark ranges with a start position and length. They will be applied to text nodes in the specified context.
library(shiny) # load a paragraph data(lorem, package = "marker") ui <- fluidPage( useMarker(), p(id = "text-to-mark", lorem), actionButton("mark", "Mark") ) server <- function(input, output){ my_marker <- marker$new("#text-to-mark") observeEvent(input$mark, { my_marker$ unmark()$ # unmark previously marked text mark_ranges(list(list(start = 5, length = 10))) # mark what is searched }) } if(interactive()) shinyApp(ui, server)
get_marked()
marker$get_marked()
A method to returned the number of keywords marked.
This requires setting send_marked
to TRUE
in
the various mark*
functions.
library(shiny) # load a paragraph data(lorem, package = "marker") ui <- fluidPage( useMarker(), p(id = "text-to-mark", lorem), actionButton("mark", "Mark"), verbatimTextOutput("marked") ) server <- function(input, output){ my_marker <- marker$new("#text-to-mark") observeEvent(input$mark, { my_marker$ unmark()$ mark_regex('[a-z]', send_marked = TRUE) }) output$marked <- renderPrint({ my_marker$get_marked() }) } if(interactive()) shinyApp(ui, server)
clone()
The objects of this class are cloneable with this method.
marker$clone(deep = FALSE)
deep
Whether to make a deep clone.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | library(shiny)
# load a paragraph
data(lorem, package = "marker")
ui <- fluidPage(
useMarker(),
p(id = "text-to-mark", lorem),
textInput("mark", "Text to mark")
)
server <- function(input, output){
my_marker <- marker$new("#text-to-mark")
observeEvent(input$mark, {
my_marker$
unmark()$ # unmark previously marked text
mark(input$mark) # mark what is searched
})
}
if(interactive())
shinyApp(ui, server)
## ------------------------------------------------
## Method `marker$new`
## ------------------------------------------------
library(shiny)
# load a paragraph
data(lorem, package = "marker")
ui <- fluidPage(
useMarker(),
p(id = "text-to-mark", lorem),
textInput("mark", "Text to mark")
)
server <- function(input, output){
my_marker <- marker$new("#text-to-mark")
observeEvent(input$mark, {
my_marker$
unmark()$ # unmark previously marked text
mark(input$mark) # mark what is searched
})
}
if(interactive())
shinyApp(ui, server)
## ------------------------------------------------
## Method `marker$mark`
## ------------------------------------------------
library(shiny)
# load a paragraph
data(lorem, package = "marker")
ui <- fluidPage(
useMarker(),
p(id = "text-to-mark", lorem),
actionButton("mark", "Mark lorem")
)
server <- function(input, output){
my_marker <- marker$new("#text-to-mark")
observeEvent(input$mark, {
my_marker$
unmark()$ # unmark previously marked text
mark("lorem") # mark what is searched
})
}
if(interactive())
shinyApp(ui, server)
## ------------------------------------------------
## Method `marker$mark_regex`
## ------------------------------------------------
library(shiny)
# load a paragraph
data(lorem, package = "marker")
ui <- fluidPage(
useMarker(),
p(id = "text-to-mark", lorem),
actionButton("mark", "Mark")
)
server <- function(input, output){
my_marker <- marker$new("#text-to-mark")
observeEvent(input$mark, {
my_marker$
unmark()$ # unmark previously marked text
mark_regex('[a-z]') # mark what is searched
})
}
if(interactive())
shinyApp(ui, server)
## ------------------------------------------------
## Method `marker$mark_ranges`
## ------------------------------------------------
library(shiny)
# load a paragraph
data(lorem, package = "marker")
ui <- fluidPage(
useMarker(),
p(id = "text-to-mark", lorem),
actionButton("mark", "Mark")
)
server <- function(input, output){
my_marker <- marker$new("#text-to-mark")
observeEvent(input$mark, {
my_marker$
unmark()$ # unmark previously marked text
mark_ranges(list(list(start = 5, length = 10))) # mark what is searched
})
}
if(interactive())
shinyApp(ui, server)
## ------------------------------------------------
## Method `marker$get_marked`
## ------------------------------------------------
library(shiny)
# load a paragraph
data(lorem, package = "marker")
ui <- fluidPage(
useMarker(),
p(id = "text-to-mark", lorem),
actionButton("mark", "Mark"),
verbatimTextOutput("marked")
)
server <- function(input, output){
my_marker <- marker$new("#text-to-mark")
observeEvent(input$mark, {
my_marker$
unmark()$
mark_regex('[a-z]', send_marked = TRUE)
})
output$marked <- renderPrint({
my_marker$get_marked()
})
}
if(interactive())
shinyApp(ui, server)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.