Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JohnCoene/marker
🖊️ Dynamically Highlight Text in Shiny
https://github.com/JohnCoene/marker
r rstats shiny
Last synced: 3 months ago
JSON representation
🖊️ Dynamically Highlight Text in Shiny
- Host: GitHub
- URL: https://github.com/JohnCoene/marker
- Owner: JohnCoene
- License: other
- Created: 2019-10-09T08:41:39.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-14T16:32:55.000Z (over 1 year ago)
- Last Synced: 2024-05-01T15:29:49.706Z (6 months ago)
- Topics: r, rstats, shiny
- Language: R
- Homepage:
- Size: 279 KB
- Stars: 54
- Watchers: 6
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-shiny-extensions - marker - Highlight text in Shiny with markjs. (UI Components / Text)
README
[![Travis build status](https://travis-ci.org/JohnCoene/marker.svg?branch=master)](https://travis-ci.org/JohnCoene/marker)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/JohnCoene/marker?branch=master&svg=true)](https://ci.appveyor.com/project/JohnCoene/marker)# marker
Highlight text in Shiny with [markjs](https://markjs.io/).
## Installation
You can install the package from Github with:
``` r
# install.packages("remotes")
remotes::install_github("JohnCoene/marker")
```## Example
Run the app above with `marker_demo()`.
🚨 Remember to always include `useMarker` at the top of your shiny UI.
``` r
library(shiny)
library(marker)data(lorem, package = "marker")
ui <- fluidPage(
useMarker(), #Â include dependencies
p(id = "text-to-mark", lorem),
textInput("text", "text to highlight")
)server <- function(input, output){
#Â initialise the marker to point at our text
marker <- marker$new("#text-to-mark")
observeEvent(input$text, {
marker$
unmark()$ #Â unmark all before we mark
mark(input$text) #Â highlight text
})}
shinyApp(ui, server)
```Plenty of options can be found in the [official documentation](https://markjs.io/).
``` r
library(shiny)
library(marker)data(lorem, package = "marker")
ui <- fluidPage(
useMarker(),
h2("Test app"),
tags$head(
tags$style(
".red{background-color:#FFB8C3;}.blue{background-color:#6ECFEA;}"
)
),
p(id = "text-to-mark",lorem),
textInput("text", "text to highlight"),
textInput("text2", "text to highlight")
)server <- function(input, output){
marker <- marker$new("#text-to-mark")
observeEvent(input$text, {
marker$
unmark(className = "red")$ # unmark red class
mark(input$text, className = "red") #Â add red class
})observeEvent(input$text2, {
marker$
unmark(className = "blue")$ # unmark blue class
mark(input$text2, className = "blue") #Â add blue class
})}
shinyApp(ui, server)
```