Giter Site home page Giter Site logo

timelyportfolio / dataui Goto Github PK

View Code? Open in Web Editor NEW
69.0 4.0 5.0 1.42 MB

data-ui for R

Home Page: https://timelyportfolio.github.io/dataui/

License: Other

R 80.04% JavaScript 19.96%
r reactjs react htmlwidgets sparklines visualization interactive vx data-ui svg

dataui's Introduction

dataui

CRAN status Lifecycle: experimental Travis build status

dataui brings the beautiful interactive visualizations of data-ui based on vx to R. Currently the package nearly fully supports sparkline and histogram, and no you do not need to know React. You will be writing React without even knowing it.

Yes, I know data-ui is in repo freeze, but I could not wait for #201. The author, now also on the vx team, has done an incredible job, so I am willing (slightly crazy) to invest the time to write this package. Plus, I sort of “need” it for a live project. Our other sparkline in R is a little old and tired (but I still very much appreciate the library) and has been frozen/unmaintained for many years.

Credits

Thanks so much to Dr. Ken Steif at Urban Spatial for sponsoring the first phase of this project and inspiring its inception.

Help

I would love for you to join me on the journey, and I will make sure that this is a friendly and welcoming place. If money is more abundant than time for you, then let me know as well.

Installation

Far from CRAN-worthy but hopefully there eventually, remotes::install_github() for now.

remotes::install_github("timelyportfolio/dataui")

Articles and Vignettes

I have prioritized vignettes and articles over proper documentation for now.

Replicate data-ui Examples

dataui and reactable

Tufte in R with dataui

Examples

Sparklines

This is is the shortest code example I could create.

library(dataui)
dui_sparkline(
  data = rnorm(50),
  components = list(dui_sparklineseries())
)

I was able to nearly fully replicate all the data-ui sparkline examples. See the vignette.

Histogram

Currently there are some examples in experiments.R. I should also note that dataui histograms also work very well as sparklines.

Below is a quick example.

library(dataui)

rn <- rnorm(1000)
ri <- runif(1000)

dui_histogram(
  binCount = 25,
  components = list(
    dui_barseries(rawData = rn, fill="#000"),
    dui_densityseries(rawData = rn, stroke = "#000"),
    dui_barseries(rawData = ri),
    dui_densityseries(rawData = ri),
    dui_xaxis(),
    dui_yaxis()
  )
)

reactable

And thanks to the fine work of Greg Lin, dataui just works with reactable. I would still like to tighten up the integration though, since the data gets duplicated in multiple spots. Here is a quick example to prove it. dataui should also work relatively well with other R table libraries.

library(dataui)
library(dplyr)
library(reactable)

data <- chickwts %>%
  group_by(feed) %>%
  summarise(weight = list(weight))

binValues = hist(chickwts$weight, breaks=15, plot = FALSE)$breaks

fillColors = scales::brewer_pal(type="qual", palette="Set2")(8)

reactable(
  data,
  columns = list(
    feed = colDef(maxWidth = 100),
    weight = colDef(
      minWidth = 400,
      cell = function(values, index) {
        dui_histogram(
          height = 200,
          width = 400,
          binValues = binValues,
          renderTooltip = htmlwidgets::JS(htmltools::HTML('
function (_ref) {
  var event = _ref.event,
      datum = _ref.datum,
      data = _ref.data,
      color = _ref.color;
  return React.createElement(
    "div",
    null,
    React.createElement(
      "strong",
      { style: { color: color } },
      datum.bin0,
      " to ",
      datum.bin1
    ),
    React.createElement(
      "div",
      null,
      React.createElement(
        "strong",
        null,
        "count "
      ),
      datum.count
    ),
    React.createElement(
      "div",
      null,
      React.createElement(
        "strong",
        null,
        "cumulative "
      ),
      datum.cumulative.toFixed(0)
    ),
    React.createElement(
      "div",
      null,
      React.createElement(
        "strong",
        null,
        "density "
      ),
      datum.density.toFixed(0)
    )
  );
}
          ')),
# reactR::babel_transform equivalent of the above
#            htmlwidgets::JS(reactR::babel_transform("
#{({ event, datum, data, color }) => (
#  <div>
#    <strong style={{ color }}>{datum.bin0} to {datum.bin1}</strong>
#    <div><strong>count </strong>{datum.count}</div>
#    <div><strong>cumulative </strong>{datum.cumulative.toFixed(0)}</div>
#    <div><strong>density </strong>{datum.density.toFixed(0)}</div>
#  </div>
#)}
#          ")),
          components = list(
            dui_barseries(rawData = values, fill = fillColors[index]),
            dui_densityseries(rawData = values, stroke = fillColors[index], fill = fillColors[index]),
            dui_xaxis()
          )
        )
      }
    )
  ),
  width = 600
)

If you use dataui in the wild, let me know and I will save a spot here for you.

Code of Conduct

Please note that the ‘dataui’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

dataui's People

Contributors

timelyportfolio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dataui's Issues

Axis limit doesn't looks right when using `dui_for_reactable()`

The Y axis limit doesn't change automatically when I used standalone sparkline version but it works well in htmlwidget version.
Am I missing something?

set.seed(123)
df = tibble(
  id = 1:3,
  plot = list(
    list(data = lapply(1:35, function(i) {
      list(
        x = paste0("Day ", i),
        gmv = sample(c(0,100,2,1,0,0,0,0,0), 9)[1]
    ) 
      })
    )
  , 
  list(data = lapply(1:35, function(i) {
    list(
      x = paste0("Day ", i),
      gmv = sample(c(0,100,2,1,0,0,0,0,0), 9)[1]
    ) 
  })
  ),
  list(data = lapply(1:35, function(i) {
    list(
      x = paste0("Day ", i),
      gmv = sample(c(10,100,20,10,100,100,1000,100,30), 9)[1]
    ) 
  })
  )
)) 
df %>% 
  reactable(
    showSortable = TRUE,
    columns = list(
      plot = colDef(
        minWidth = 150,
        align = "center",
        filterable = FALSE,
        sortable = FALSE,
        cell = dui_for_reactable(
          dui_sparkline(
            height = 100,
            margin = list(left = 50, top = 50),
            data = htmlwidgets::JS("cellInfo.value.data"),
            valueAccessor =  htmlwidgets::JS("(d) => d.gmv"),
            components = list(
              dui_sparklineseries(),
              dui_sparkpointseries()
            )
          )  
        )
      )
    )) %>% 
  dataui::dui_add_reactable_dep() 

standalone

df %>% 
  reactable(
    showSortable = TRUE,
    columns = list(
      plot = colDef(
        minWidth = 150,
        align = "center",
        filterable = FALSE,
        sortable = FALSE,
        cell = function(value)(
          dui_sparkline(
            data = value$data,
            valueAccessor =  htmlwidgets::JS("(d) => d.gmv"),
            components = list(
              dui_sparklineseries(),
              dui_sparkpointseries()
            )
          )
        )
      )
    )) 

htmlwidget

document

I believe the API is stable enough to begin documenting in roxygen and also in other supplementary materials, such as vignettes and articles.

tests

Write tests before this gets out of hand. Some complicated logic that I would like to make sure gets tested:

  • responsive behavior

dui_for_reactable helper preventing flexdashboard from rendering reactable with sparkline

RMarkdown script and supporting files are here. This is the reactable chunk,

# sparkline column for cases per 100k trend
cases_spark <- function(class = NULL, ...) {
      colDef(
            name = "Cases per 100K Trend",
            cell = dui_for_reactable(
                  dui_sparkline(
                        data = htmlwidgets::JS("cellInfo.value.cases_list"),
                        valueAccessor = htmlwidgets::JS("(d) => d.cases[0]"),
                        renderTooltip = htmlwidgets::JS(
                              htmltools::HTML(
                                    "function (_ref) {
                   var datum = _ref.datum;
                   return React.createElement(
                       'div',
                       {style: {margin: 0, padding: 0}},
                       datum.date && React.createElement(
                         'div',
                         {style: {
                           backgroundColor: 'black', color: 'white',
                           padding: '4px 0px', margin: 0, textAlign: 'center'
                         }},
                         // good reference https://observablehq.com/@mbostock/date-formatting
                         //   for built-in JavaScript formatting
                         //   but need to convert string to Date with new Date()
                         new Date(datum.date).toLocaleString(undefined, {
                          'month': 'numeric',
                          'day': '2-digit'
                        })
                       ),
                       React.createElement(
                         'div',
                         {style: {fontWeight: 'bold', fontSize: '1.2em', padding: '6px 0'}},
                         datum.y ? datum.y.toLocaleString(undefined, {maximumFractionDigits: 0}) : '--'
                       )
                   );
                  }"
                              )),
                        components = list(
                              dui_sparklineseries(
                                    showLine = FALSE,
                                    showArea = TRUE,
                                    fill = htmlwidgets::JS("cellInfo.original.cases_color"),
                                    fillOpacity = 0.6                              ),
                              dui_sparkpointseries(
                                    points = list("max"),
                                    fill = htmlwidgets::JS("cellInfo.original.cases_color"),
                                    stroke = htmlwidgets::JS("cellInfo.original.cases_color"),
                                    renderLabel = htmlwidgets::JS("(d) => d.toFixed(0)"),
                                    labelPosition = "left",
                                    size = 3
                              )
                        )
                  )
            )
      )
}


posrate_spark <- function(class = NULL, ...){
      colDef(
            name = "Positive Test Rate Trend",
            cell = function(value, index) {
                  if(is.null(value)) return(dui_sparkline())
                  dui_sparkline(
                        data = value[[1]],
                        valueAccessor = htmlwidgets::JS("(d) => d.posRate"),
                        renderTooltip = htmlwidgets::JS(
                           htmltools::HTML(
                              "function (_ref) {
                                 var datum = _ref.datum;
                                 return React.createElement(
                                     'div',
                                     {style: {margin: 0, padding: 0}},
                                    datum.endDate && React.createElement(
                                       'div',
                                       {style: {
                                         backgroundColor: 'black', color: 'white',
                                         padding: '4px 0px', margin: 0, textAlign: 'center'
                                       }},
                                       new Date(datum.endDate).toLocaleString(undefined, {
                                         'month': 'numeric',
                                         'day': '2-digit'
                                       })
                                    ),
                                    React.createElement(
                                       'div',
                                       {style: {fontWeight: 'bold', fontSize: '1.2em', padding: '6px 0'}},
                                       datum.y ? datum.y.toLocaleString(undefined, {maximumFractionDigits: 0, style: 'percent'}) : '--'
                                    )
                                 );
                              }"
                           )
                        ),
                        components = list(
                              # dui_sparkpatternlines(
                              #    id = "band_pattern_misc",
                              #    height = 4,
                              #    width = 4,
                              #    stroke = posrate_col[index],
                              #    strokeWidth = 1,
                              #    orientation = list('diagonal')
                              # ),
                              # dui_sparkbandline(
                              #    band = list( from = list( y = 0 ), to = list( y = 0.05 ) ),
                              #    fill = "url(#band_pattern_misc)"
                              # ),
                              dui_sparklineseries(
                                    stroke = posrate_col[index]
                              )
                        )
                  )
            }
      )
}

reactable(
      data = react_dat,
      borderless = TRUE,
      style = list(fontSize = "18px"),
      defaultPageSize = 5,
      defaultSortOrder = "desc",
      defaultSorted = "cases_100k",
      defaultColDef = colDef(
            align = "center",
            headerStyle = "align-self: flex-end; font-weight:normal;"
      ),
      rowStyle = list(
            alignItems = "center",
            # add back border here
            borderBottom = "1px solid lightgray"
      ),
      highlight = TRUE,
      columns = list(
            cases_color = colDef(show = FALSE),
            # pos_color = colDef(show = FALSE),
            msa = colDef(
                  name = "Metropolitan Statistical Area"
            ),
            cases_100k = colDef(
                  name = "Cases per 100K",
            ),
            pos_rate = colDef(
                  name = "Positive Test Rate",
                  na = "",
                  format = colFormat(percent = TRUE, digits = 1)
            ),
            # casesList = cases_spark(),
            # posList = posrate_spark(),
            casesList = colDef(show = FALSE),
            posList = colDef(show = FALSE)
      )
) %>% 
      dui_add_reactable_dep()

I have two sparkline columns in my reactable. casesList uses the dui_for_reactable helper and posList (currently) does not. The dui_add_reactable_dep does seem to be necessary whether the dui_for_reactable function is used or not. The chunk inside the Rmd does render with both sparkline columns. The rendering problem only happens when the Rmd is knitted.

With posList and dui_add_reactable_dep
dash-pos-duidep

With caseList and dui_add_reactable_dep
dash-cases-duidep

current session info
- Session info ---------------------------------------------------------------------------
 setting  value                       
 version  R version 3.6.2 (2019-12-12)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United States.1252  
 ctype    English_United States.1252  
 tz       America/New_York            
 date     2020-07-23                  

- Packages -------------------------------------------------------------------------------
 package       * version  date       lib source                       
 assertthat      0.2.1    2019-03-21 [1] CRAN (R 3.6.2)               
 cli             2.0.2    2020-02-28 [1] CRAN (R 3.6.3)               
 crayon          1.3.4    2017-09-16 [1] CRAN (R 3.6.2)               
 crosstalk       1.1.0.1  2020-03-13 [1] CRAN (R 3.6.3)               
 digest          0.6.25   2020-02-23 [1] CRAN (R 3.6.2)               
 dplyr         * 1.0.0    2020-05-29 [1] CRAN (R 3.6.3)               
 ellipsis        0.3.0    2019-09-20 [1] CRAN (R 3.6.2)               
 evaluate        0.14     2019-05-28 [1] CRAN (R 3.6.1)               
 fansi           0.4.1    2020-01-08 [1] CRAN (R 3.6.2)               
 flexdashboard   0.5.1.1  2018-06-29 [1] CRAN (R 3.6.1)               
 generics        0.0.2    2018-11-29 [1] CRAN (R 3.6.2)               
 glue            1.4.1    2020-05-13 [1] CRAN (R 3.6.3)               
 hms             0.5.3    2020-01-08 [1] CRAN (R 3.6.2)               
 htmltools       0.5.0    2020-06-16 [1] CRAN (R 3.6.3)               
 htmlwidgets     1.5.1    2019-10-08 [1] CRAN (R 3.6.1)               
 jsonlite        1.7.0    2020-06-25 [1] CRAN (R 3.6.3)               
 knitr           1.28     2020-02-06 [1] CRAN (R 3.6.2)               
 leaflet         2.0.3    2019-11-16 [1] CRAN (R 3.6.3)               
 lifecycle       0.2.0    2020-03-06 [1] CRAN (R 3.6.3)               
 magrittr        1.5      2014-11-22 [1] CRAN (R 3.6.2)               
 pacman          0.5.1    2019-03-11 [1] CRAN (R 3.6.2)               
 pillar          1.4.3    2019-12-20 [1] CRAN (R 3.6.2)               
 pkgconfig       2.0.3    2019-09-22 [1] CRAN (R 3.6.2)               
 purrr           0.3.3    2019-10-18 [1] CRAN (R 3.6.2)               
 R6              2.4.1    2019-11-12 [1] CRAN (R 3.6.2)               
 Rcpp            1.0.4.6  2020-04-09 [1] CRAN (R 3.6.3)               
 readr           1.3.1    2018-12-21 [1] CRAN (R 3.6.2)               
 renv            0.9.3-30 2020-02-22 [1] Github (rstudio/renv@916923a)
 rlang           0.4.7    2020-07-09 [1] CRAN (R 3.6.3)               
 rmarkdown       2.1      2020-01-20 [1] CRAN (R 3.6.2)               
 rstudioapi      0.11     2020-02-07 [1] CRAN (R 3.6.2)               
 sessioninfo     1.1.1    2018-11-05 [1] CRAN (R 3.6.2)               
 tibble          3.0.0    2020-03-30 [1] CRAN (R 3.6.2)               
 tidyselect      1.1.0    2020-05-11 [1] CRAN (R 3.6.3)               
 vctrs           0.3.2    2020-07-15 [1] CRAN (R 3.6.2)               
 withr           2.1.2    2018-03-15 [1] CRAN (R 3.6.1)               
 xfun            0.12     2020-01-13 [1] CRAN (R 3.6.2)               
 yaml            2.2.1    2020-02-01 [1] CRAN (R 3.6.2)               

[1] C:/Users/tbats/Documents/R/Projects/Indiana-COVIDcast-Dashboard/renv/library/R-3.6/x86_64-w64-mingw32
[2] C:/Users/tbats/AppData/Local/Temp/Rtmp88qPaq/renv-system-library

Different diagonal fill colours for multiple sparklines

I would like the colour of the diagonal fill to match the color of the sparkline.

So, in the code below, Company A will have a green line with green diagonal fill underneath and company B will have a red line with red diagonal fill underneath.

I can't seem to get the diagonal fill to take on more than one value.

library("tidyverse")
library("dataui")
library("reactable")

df <- tibble(
  Company = c("A", "B"),
  Line = list(list(c(1, 2, 1)), list(c(2, 2, 1)))
)

colpal <- c("#00DA07", "#BB0337")

rt1 <- reactable(df,
        compact = TRUE,
        fullWidth = FALSE,
                 
        columns = list(
          Line = colDef(
            cell = function(value, index) {
              dui_sparkline(
                data = value[[1]], 
                height = 80,
                components = list(
                  dui_sparklineseries(
                    curve = "linear",
                    showArea = TRUE,
                    fill = "url(#area_pattern2)",
                    stroke = colpal[index]),
                  
                  # Diagonal fill lines
                  dui_sparkpatternlines(
                    id = "area_pattern2",
                    height = 4,
                    width = 4,
                    stroke =  colpal[index],
                    strokeWidth = 1,
                    orientation = "diagonal"
                  )
                  
                )
              )
            }
          )
        )
)
rt1

Composite Sparkline

Is there any way to combine to sparklines in one plot similar the approach on this SO post?

Thanks for a great package!

tooltip date text, overlapping fixed text, linear gradient vector indexing for sparklines inside a reactable

The code and files I'm using are here, but I'll post what I think are the salient chunks.

pacman::p_load(swatches, dplyr, glue, extrafont, reactable, dataui)

# color palette
cases_col <- map2_current %>% 
   select(msa, cases_100k) %>% 
   # slice(n()) %>% 
   mutate(cases_100k = round(cases_100k, 2),
          color = case_when(cases_100k < 1 ~ moody[[1]],
                            between(cases_100k, 1, 9.99) ~ moody[[2]],
                            between(cases_100k, 10, 24.99) ~ moody[[3]],
                            cases_100k >= 25 ~ moody[[4]])) %>% 
   arrange(desc(cases_100k)) %>% 
   pull(color)

# cases trend data
cases_hist <- map2_hist %>%  
   select(date, msa, cases_100k) %>% 
   # mutate(date = as.character(date),
   #        date = stringr::str_replace_all(date, "-", "/"),
   #        date = stringr::str_remove(date, "^[0-9]*/")) %>%
   # mutate(date = format(date, format = "%B %d")) %>%
   mutate(cases_100k = round(cases_100k, 0)) %>% 
   group_by(msa) %>% 
   summarize(cases_list = mapply(function (date, cases)
   {list(date = date, cases = cases)},
   date, cases_100k,
   SIMPLIFY = FALSE)) %>% 
   tidyr::nest() %>%
   mutate(data = purrr::map(data, ~as.list(.x))) %>%
   rename(casesList = data)

# current cases per 100K and positivity rates
current_dat <- map2_current %>%
   select(msa, cases_100k, pos_rate) %>% 
   mutate(cases_100k = round(cases_100k, 0))

react_dat <- purrr::reduce(list(current_dat, cases_hist), left_join, by = "msa") %>% 
   arrange(desc(cases_100k))

react_tbl <- reactable(
   data = react_dat,
   borderless = TRUE,
   # compact = TRUE,
   # fullWidth = FALSE,
   # width = 600,
   defaultPageSize = 5,
   defaultColDef = colDef(
      align = "center"
   ),
   highlight = TRUE,
   columns = list(
      msa = colDef(
         name = "Metropolitan Statistical Area"
      ),
      cases_100k = colDef(
         name = "Cases per 100K",
      ),
      pos_rate = colDef(
         name = "Positive Test Rate",
         na = "",
         format = colFormat(percent = TRUE, digits = 1)
      ),
      casesList = colDef(
         name = "Cases per 100K Trend",
         cell = function(value, index) {
            dui_sparkline(
               data = value[[1]],
               valueAccessor = htmlwidgets::JS("(d) => d.cases"),
               renderTooltip = htmlwidgets::JS(
                  htmltools::HTML(
                     "function (_ref) {
                                             var datum = _ref.datum;
                                             return React.createElement(
                                                 'div',
                                                 {style: {margin: 0, padding: 0}},
                                                 datum.date && React.createElement(
                                                   'div',
                                                   {style: {
                                                     backgroundColor: 'black', color: 'white',
                                                     padding: '4px 0px', margin: 0, textAlign: 'center'
                                                   }},
                                                   datum.date
                                                 ),
                                                 React.createElement(
                                                   'div',
                                                   {style: {fontWeight: 'bold', fontSize: '1.2em', padding: '6px 0'}},
                                                   datum.y ? datum.y.toLocaleString(undefined, {maximumFractionDigits: 0}) : \"--\"
                                                 )
                                             );
                                           }"
                  )),
               components = list(                 
                  # dui_sparklineargradient(
                  #    id = "cases_gradient",
                  #    to = cases_col_grad[index],
                  #    from = cases_col[index],
                  #    fromOffset = "80%"
                  # ),
                  dui_sparklineseries(
                     showLine = FALSE,
                     showArea = TRUE,
                     fill = cases_col[index],
                     fillOpacity = 0.6
                     # stroke = cases_col[index],
                     # showLine = TRUE,
                     # fillOpacity = htmlwidgets::JS("(d, i) => (i === 24 ? 1 : 0.5)"),
                     # fill = "url(#cases_gradient)",
                  ),
                  dui_sparkpointseries(
                     points = list("max"),
                     fill = cases_col[index],
                     stroke = cases_col[index],
                     renderLabel = htmlwidgets::JS("(d) => d.toLocaleString(undefined, {maximumFractionDigits: 0})"),
                     labelPosition = "left",
                     size = 3
                  )
               )
            )
         }
      )
   )
)
react_tbl

reactable-100k

  1. Tooltip date - I've taken the tooltip code from your kitchen sink and tufte examples. ( I don't speak a lick of js), and I can't spot where I'm going wrong. I'm trying to go from ymd format to a Month day or month/day format in the tooltip. In cases_hist, I've commented out the different date code I've tried. If I try to use any of those it completely breaks the sparkline.
  2. Overlapping fixed text - On the Cincinnati line in the image of the table, you can see the overlapping 12s in the sparkline where there are multiple points with the maximum. This probably isn't a reasonable ask, but I was wondering if there's a solution to this, like a ggrepel, besides adding some extra decimals until I get a unique maximum. I'd rather not add the extra precision to this number if I don't have to.
  3. linear gradient vector indexing - After, uncommenting dui_sparklineargradient and exchanging the fill args in dui_sparklineseries, the chicago fill color ended up wrong. The fixed point color remained correct, though.
    react-gradfill

Thank you very much for the package and I'd appreciate any help you can give.

current session info
- Session info -------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.6.2 (2019-12-12)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United States.1252  
 ctype    English_United States.1252  
 tz       America/New_York            
 date     2020-07-20                  

- Packages -----------------------------------------------------------------------------------------------------------------------------------------
 package      * version  date       lib source                                 
 assertthat     0.2.1    2019-03-21 [1] CRAN (R 3.6.2)                         
 backports      1.1.6    2020-04-05 [1] CRAN (R 3.6.3)                         
 cli            2.0.2    2020-02-28 [1] CRAN (R 3.6.3)                         
 clipr          0.7.0    2019-07-23 [1] CRAN (R 3.6.2)                         
 colorspace     1.4-1    2019-03-18 [1] CRAN (R 3.6.1)                         
 crayon         1.3.4    2017-09-16 [1] CRAN (R 3.6.2)                         
 crosstalk      1.1.0.1  2020-03-13 [1] CRAN (R 3.6.3)                         
 dataui       * 0.0.1    2020-07-18 [1] Github (timelyportfolio/dataui@39583c6)
 desc           1.2.0    2018-05-01 [1] CRAN (R 3.6.1)                         
 details      * 0.2.1    2020-01-12 [1] CRAN (R 3.6.3)                         
 digest         0.6.25   2020-02-23 [1] CRAN (R 3.6.2)                         
 dplyr        * 1.0.0    2020-05-29 [1] CRAN (R 3.6.3)                         
 ellipsis       0.3.0    2019-09-20 [1] CRAN (R 3.6.2)                         
 evaluate       0.14     2019-05-28 [1] CRAN (R 3.6.1)                         
 extrafont    * 0.17     2014-12-08 [1] CRAN (R 3.6.0)                         
 extrafontdb    1.0      2012-06-11 [1] CRAN (R 3.6.0)                         
 fansi          0.4.1    2020-01-08 [1] CRAN (R 3.6.2)                         
 farver         2.0.3    2020-01-16 [1] CRAN (R 3.6.2)                         
 generics       0.0.2    2018-11-29 [1] CRAN (R 3.6.2)                         
 glue         * 1.4.1    2020-05-13 [1] CRAN (R 3.6.3)                         
 hms            0.5.3    2020-01-08 [1] CRAN (R 3.6.2)                         
 htmltools      0.5.0    2020-06-16 [1] CRAN (R 3.6.3)                         
 htmlwidgets    1.5.1    2019-10-08 [1] CRAN (R 3.6.1)                         
 httr           1.4.1    2019-08-05 [1] CRAN (R 3.6.1)                         
 jsonlite       1.7.0    2020-06-25 [1] CRAN (R 3.6.3)                         
 knitr          1.28     2020-02-06 [1] CRAN (R 3.6.2)                         
 leaflet        2.0.3    2019-11-16 [1] CRAN (R 3.6.3)                         
 lifecycle      0.2.0    2020-03-06 [1] CRAN (R 3.6.3)                         
 magrittr       1.5      2014-11-22 [1] CRAN (R 3.6.2)                         
 munsell        0.5.0    2018-06-12 [1] CRAN (R 3.6.1)                         
 pack           0.1-1    2019-05-28 [1] local                                  
 pacman         0.5.1    2019-03-11 [1] CRAN (R 3.6.2)                         
 pillar         1.4.3    2019-12-20 [1] CRAN (R 3.6.2)                         
 pkgconfig      2.0.3    2019-09-22 [1] CRAN (R 3.6.2)                         
 png            0.1-7    2013-12-03 [1] CRAN (R 3.6.0)                         
 prismatic      0.2.0    2019-12-01 [1] CRAN (R 3.6.3)                         
 purrr          0.3.3    2019-10-18 [1] CRAN (R 3.6.2)                         
 R6             2.4.1    2019-11-12 [1] CRAN (R 3.6.2)                         
 RColorBrewer   1.1-2    2014-12-07 [1] CRAN (R 3.6.0)                         
 Rcpp           1.0.4.6  2020-04-09 [1] CRAN (R 3.6.3)                         
 reactable    * 0.2.0    2020-05-28 [1] CRAN (R 3.6.3)                         
 reactR         0.4.3    2020-07-12 [1] CRAN (R 3.6.2)                         
 readr          1.3.1    2018-12-21 [1] CRAN (R 3.6.2)                         
 renv           0.9.3-30 2020-02-22 [1] Github (rstudio/renv@916923a)          
 rlang          0.4.7    2020-07-09 [1] CRAN (R 3.6.3)                         
 rmarkdown      2.1      2020-01-20 [1] CRAN (R 3.6.2)                         
 rprojroot      1.3-2    2018-01-03 [1] CRAN (R 3.6.1)                         
 rstudioapi     0.11     2020-02-07 [1] CRAN (R 3.6.2)                         
 Rttf2pt1       1.3.8    2020-01-10 [1] CRAN (R 3.6.2)                         
 scales         1.1.0    2019-11-18 [1] CRAN (R 3.6.2)                         
 sessioninfo    1.1.1    2018-11-05 [1] CRAN (R 3.6.2)                         
 stringi        1.4.6    2020-02-17 [1] CRAN (R 3.6.2)                         
 stringr        1.4.0    2019-02-10 [1] CRAN (R 3.6.2)                         
 swatches     * 0.5.0    2017-12-21 [1] CRAN (R 3.6.1)                         
 tibble         3.0.0    2020-03-30 [1] CRAN (R 3.6.2)                         
 tidyr          1.0.2    2020-01-24 [1] CRAN (R 3.6.2)                         
 tidyselect     1.1.0    2020-05-11 [1] CRAN (R 3.6.3)                         
 vctrs          0.3.2    2020-07-15 [1] CRAN (R 3.6.2)                         
 withr          2.1.2    2018-03-15 [1] CRAN (R 3.6.1)                         
 xfun           0.12     2020-01-13 [1] CRAN (R 3.6.2)                         
 xml2           1.3.2    2020-04-23 [1] CRAN (R 3.6.3)                         
 yaml           2.2.1    2020-02-01 [1] CRAN (R 3.6.2)                         

[1] C:/Users/tbats/Documents/R/Projects/Indiana-COVIDcast-Dashboard/renv/library/R-3.6/x86_64-w64-mingw32
[2] C:/Users/tbats/AppData/Local/Temp/RtmpAVvpMO/renv-system-library

Add improved tooltip to dataui with reactable?

Here is a tooltip that is easy to read because of its placement and white background.

library("dataui")

dui_sparkline(
  data = runif(30, 0, 20),
  width = 500,
  height = 100,
  margin = list( top= 24, right= 72, bottom= 24, left= 8 ),
  ariaLabel = "sparkline misc example",
  renderTooltip = htmlwidgets::JS("({ datum }) => datum.y.toFixed(2)"),
  components = c(
    lapply(
      1:30 - 1,
      function(i) {
        dui_sparkverticalrefline(
          key = i,
          reference = i,
          stroke = "#8ce99a",
          strokeWidth = 1,
          strokeLinecap = "square",
          strokeDasharray = "2,2"
        )
      }
    ),
    list(
      dui_sparklineseries(
        stroke = "#40c057"
      ),
      dui_sparkpointseries(
        points = list('all'),
        fill = "#8ce99a"
      ),
      dui_tooltip(
        components = list(
          dui_sparkhorizontalrefline(
            key = "ref-hline",
            strokeWidth = 1,
            stroke = "#c2255c",
            strokeDasharray = "4,4"
          ),
          dui_sparkverticalrefline(
            key = "ref-vline",
            strokeWidth = 1,
            stroke = "#c2255c",
            strokeDasharray = "4,4"
          ),
          dui_sparkpointseries(
            key = "ref-point",
            fill = "#c2255c"
          )
        )
      )
    )
  )
)

How do I add this type of tooltip to this example that uses Reactable?

library("tidyverse")
library("dataui")
library("reactable")

df <- tibble(
  Company = c("A", "B"),
  Line = list(list(c(1, 2, 1)), list(c(2, 2, 1)))
)

colpal <- c("#00DA07", "#BB0337")

rt1 <- reactable(df,
        compact = TRUE,
        fullWidth = FALSE,
                 
        columns = list(
          Line = colDef(
            cell = function(value, index) {
              dui_sparkline(
                data = value[[1]], 
                height = 80,
                margin = list(top = 20, right = 20, bottom = 20, left = 20),
                
                components = list(
                  dui_sparklineseries(
                    curve = "linear",
                    showArea = TRUE,
                    fill = "url(#area_pattern2)",
                    stroke = colpal[index]),
                  
                  dui_tooltip(components = list(
                    dui_sparkverticalrefline(
                      #styling
                      strokeDasharray = "4,4",
                      stroke = gray.colors(10)[3]
                    ),
                    dui_sparkpointseries(
                      #styling
                      stroke = colpal[index],
                      fill = "#fff",
                      #litle extra interactivity for demostration purposes
                      renderLabel = htmlwidgets::JS("(d) => d.toFixed(2)")
                    )
                  ))
                )
              )
            }
          )
        )
)
rt1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.