Title: | 'jQuery' Sparkline 'htmlwidget' |
---|---|
Description: | Include interactive sparkline charts <http://omnipotent.net/jquery.sparkline> in all R contexts with the convenience of 'htmlwidgets'. |
Authors: | Ramnath Vaidyanathan [aut, cre], Kent Russell [aut, ctb], Gareth Watts [aut, cph] (jquery.sparkline library in htmlwidgets/lib, https://github.com/gwatts/jquery.sparkline), jQuery Foundation [cph] (jQuery library), jQuery contributors [ctb, cph] (jQuery library; authors listed in inst/htmlwidgets/lib/jquery/jquery-AUTHORS.txt) |
Maintainer: | Ramnath Vaidyanathan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 2.0 |
Built: | 2024-11-12 04:40:51 UTC |
Source: | https://github.com/htmlwidgets/sparkline |
An HTML dependency for sparkline
html_dependency_sparkline()
html_dependency_sparkline()
Create interactive sparklines for inline visualization.
sparkline(values, ..., width = 60, height = 20, elementId = NULL, renderSelector = NULL)
sparkline(values, ..., width = 60, height = 20, elementId = NULL, renderSelector = NULL)
values |
|
... |
additional options passed to |
height , width
|
height and width of sparkline htmlwidget
specified in any valid |
elementId |
|
renderSelector |
|
Output and render functions for using sparkline within Shiny applications and interactive Rmd documents.
sparklineOutput(outputId, width = "60px", height = "20px") renderSparkline(expr, env = parent.frame(), quoted = FALSE)
sparklineOutput(outputId, width = "60px", height = "20px") renderSparkline(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a sparkline |
env |
The environment in which to evaluate |
quoted |
Is |
Add Sparkline Dependencies to Tag or 'htmlwidget'
spk_add_deps(tag_htmlwidget = NULL)
spk_add_deps(tag_htmlwidget = NULL)
tag_htmlwidget |
|
shiny.tag
or htmlwidget
# use spk_add_deps with other htmlwidgets library(sparkline) library(formattable) fw <- as.htmlwidget( formattable( data.frame( id = c("a", "b"), sparkline = c( spk_chr(runif(10,0,10), type="bar"), spk_chr(runif(10,0,5), type="bar") ), stringsAsFactors = FALSE ) ) ) spk_add_deps(fw) # use spk_add_deps with htmltools/shiny tags library(sparkline) library(htmltools) div <- tags$div( spk_chr(1:10, type="bar") ) spk_add_deps(div)
# use spk_add_deps with other htmlwidgets library(sparkline) library(formattable) fw <- as.htmlwidget( formattable( data.frame( id = c("a", "b"), sparkline = c( spk_chr(runif(10,0,10), type="bar"), spk_chr(runif(10,0,5), type="bar") ), stringsAsFactors = FALSE ) ) ) spk_add_deps(fw) # use spk_add_deps with htmltools/shiny tags library(sparkline) library(htmltools) div <- tags$div( spk_chr(1:10, type="bar") ) spk_add_deps(div)
Create a character version ofinteractive sparklines for use with other 'htmlwidgets' or tags.
spk_chr(values, ..., width = 60, height = 20, elementId = NULL, renderSelector = NULL)
spk_chr(values, ..., width = 60, height = 20, elementId = NULL, renderSelector = NULL)
values |
|
... |
additional options passed to |
width |
height and width of sparkline htmlwidget
specified in any valid |
height |
height and width of sparkline htmlwidget
specified in any valid |
elementId |
|
renderSelector |
|
## Not run: #spk_chr works well with dplyr summarise library(dplyr) library(sparkline) library(formattable) mtcars %>% group_by(cyl) %>% summarise( hp = spk_chr( hp, type="box", chartRangeMin=0, chartRangeMax=max(mtcars$hp) ), mpg = spk_chr( mpg, type="box", chartRangeMin=0, chartRangeMax=max(mtcars$mpg) ) ) %>% formattable() %>% formattable::as.htmlwidget() %>% spk_add_deps() ## End(Not run)
## Not run: #spk_chr works well with dplyr summarise library(dplyr) library(sparkline) library(formattable) mtcars %>% group_by(cyl) %>% summarise( hp = spk_chr( hp, type="box", chartRangeMin=0, chartRangeMax=max(mtcars$hp) ), mpg = spk_chr( mpg, type="box", chartRangeMin=0, chartRangeMax=max(mtcars$mpg) ) ) %>% formattable() %>% formattable::as.htmlwidget() %>% spk_add_deps() ## End(Not run)
Add a Composite to an Existing Sparkline
spk_composite(sparkline = NULL, sparklineToAdd = NULL, ...)
spk_composite(sparkline = NULL, sparklineToAdd = NULL, ...)
sparkline |
|
sparklineToAdd |
|
... |
extra arguments to modify |
sparkline
object
library(sparkline) sl1 <- sparkline( c(5,4,5,-2,0,3), type='bar', barColor="#aaf", chartRangeMin=-5, chartRangeMax=10, # set an id that will make it easier to refer # in the next sparkline elementId="sparkline-for-composite" ) sl2 <- sparkline( c(4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7), type="line", fillColor = FALSE, lineColor ='red', chartRangeMin = -5, chartRangeMax = 10 ) # add sparkline as a composite spk_composite(sl1, sl2) # add values and options as a composite spk_composite( sl1, values=c(4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7), options = list( type="line", fillColor = FALSE, lineColor ='red', chartRangeMin = -5, chartRangeMax = 10 ) ) # add combination of sparkline and options as a composite spk_composite( sl1, sl2, options = list( type="box" ) )
library(sparkline) sl1 <- sparkline( c(5,4,5,-2,0,3), type='bar', barColor="#aaf", chartRangeMin=-5, chartRangeMax=10, # set an id that will make it easier to refer # in the next sparkline elementId="sparkline-for-composite" ) sl2 <- sparkline( c(4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7), type="line", fillColor = FALSE, lineColor ='red', chartRangeMin = -5, chartRangeMax = 10 ) # add sparkline as a composite spk_composite(sl1, sl2) # add values and options as a composite spk_composite( sl1, values=c(4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7), options = list( type="line", fillColor = FALSE, lineColor ='red', chartRangeMin = -5, chartRangeMax = 10 ) ) # add combination of sparkline and options as a composite spk_composite( sl1, sl2, options = list( type="box" ) )