MyNixOS website logo
Description

Shiny Searchbar - An Input Widget for Highlighting Text and More.

Add a searchbar widget to your 'Shiny' application. The widget quickly integrates with any existing element containing text to highlight matches. Highlighting is done with the 'JavaScript' library 'mark.js'. The widget includes buttons to cycle through multiple instances of the match and automatically scroll to the matches in an overflow element (or window). The widget also displays the total number of matches and which match is currently being cycled through. The widget is structured as a 'Bootstrap 3' input group.

Shiny Searchbar

CRAN status

The shinySearchbar package adds an easy-to-implement searchbar widget to your R Shiny application with searchbar().

  • Highlight search terms within an element containing text (highlighting is done with mark.js)
  • Cycle through matches with automatic scrolling in an overflow window or elements
  • Quickly displays feedback on the number of matches
  • Bootstrap 3 input group widget

Shiny Searchbar Demo

Getting Started

Installation

# Install the development version from GitHub:
devtools::install_github("jes-n/shiny-searchbar")

Demo

Try the demo on shinyapps here!

It is also included in the installation and can be run locally with the following (in the R command line):

shinySearchbar:::demo()

The demo provides examples of the searchbar widget in-action and a configuration tool to play around with the interface and mark.js options, along with automatically generating the corresponding searchbar() function call.

Usage

The searchbar widget is added to the UI portion of an R Shiny application using the function searchbar(inputId, contextId). The function requires an inputId to assign as the id attribute of its own element and a contextId, the id attribute of the element containing text, to search and highlight.

The following snippet is the a very basic Shiny application, including searchbar() and a text element:

library(shiny)
library(shinySearchbar)

ui <- fluidPage(
  searchbar("sb", "text"),
  textOutput("text")
)

server <- function(input, output) {
  output$text <- renderText("Hello world!")
}

shinyApp(ui, server)

Options

searchbar(inputId, contextId, value=NULL, label=NULL, width=NULL, placeholder=NULL,
  counter=TRUE, cycler=TRUE, scrollBehavior=c("smooth", "auto"),
  markOpts=shinySearchbar:::configurator, quiet=FALSE
)

The searchbar widget includes the standard Shiny input widget arguments (value, label, width, and placeholder).

The widget also provides interface options: counter and cycler. These options add functionality to the widget. The counter provides the user with feedback on the number of matches found. The cycler adds next and previous buttons to cycle between the matches. This can also be done with the Enter (next) or Shift+Enter (previous) keys. The cycler uses the scrollBehavior argument ("auto" or "smooth") for automatic or smooth scrolling between matches when the text element has overflow.

Finally, the markOpts list sets the options that are passed to the underlying mark.js API. Extensive (but not fool-proof) validation is performed on the arguments to the markOpts list, to ensure it conforms to the API. The warnings generated by this validation step can be suppressed using quiet=TRUE.

configurator <- list(
  element="mark",
  className="",
  exclude=c(),
  accuracy=c("partially", "complementary", "exactly"),
  synonyms=list(),
  ignorePunctuation=c(),
  wildcards=c("disabled", "enabled", "withSpaces"),
  iframes=FALSE,
  iframesTimeout=5000,
  separateWordSearch=TRUE,
  diacritics=TRUE,
  acrossElements=FALSE,
  caseSensitive=FALSE,
  ignoreJoiners=FALSE,
  debug=FALSE
)

See the documentation and the demo for more examples of all these options. For detailed information on the mark.js specific options, see its API and interactive Configurator.

Acknowledgments

  • This widget uses mark.js for highlighting the search terms and determining the number of matches. It was also inspired by the "jump to matches" example provided by the same library.
  • The gadenbuie/lorem R package on GitHub was used to generate the Lorem Ipsum text used in the demos.
Metadata

Version

1.0.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows