Search code examples
rknitrr-markdownplotlyioslides

formattable in my rMarkdown ioslides_presentation doesn't work


I'm trying to use an example (link) of formattable in my rMarkdown ioslides_presentation document. Everything works fine but table in the slide doesn't look like if I run it just from R without knitting HTML.

```{r echo=FALSE, results='asis',error=F, warning=F}
library(formattable)
library(plotly)

DF <- data.frame(Ticker=c("", "", "", "IBM", "AAPL", "MSFT"),
                 Name=c("Dow Jones", "S&P 500", "Technology", 
                        "IBM", "Apple", "Microsoft"),
                 Value=accounting(c(15988.08, 1880.33, NA, 
                                    130.00, 97.05, 50.99)),
                 Change=percent(c(-0.0239, -0.0216, 0.021, 
                                  -0.0219, -0.0248, -0.0399)))
DF

formattable(DF, list(
  Name=formatter(
    "span",
    style = x ~ ifelse(x == "Technology", 
                       formattable::style(font.weight = "bold"), NA)),
  Value = color_tile("white", "orange"),
  Change = formatter(
    "span",
    style = x ~ formattable::style(color = ifelse(x < 0 , "red", "green")),
    x ~ icontext(ifelse(x < 0, "arrow-down", "arrow-up"), x)))
)

```

How can I get the same appearance of the table in my ioslides_presentation?


Solution

  • Add the following stylesheet:

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    

    You could also make it locally available since the above solution would require a internet connection even if you use self_contained: true in your YAML header.