【问题标题】:formattable in my rMarkdown ioslides_presentation doesn't work我的 rMarkdown ioslides_presentation 中的 formattable 不起作用
【发布时间】:2016-10-18 07:32:04
【问题描述】:

我正在尝试在我的 rMarkdown ioslides_presentation 文档中使用 formattable 的示例 (link)。一切正常,但如果我只从 R 运行它而不编写 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)))
)

```

如何在 ioslides_presentation 中获得与表格相同的外观?

【问题讨论】:

  • 只是桌子的宽度让你烦恼吗?然后你可以添加&lt;style&gt; .table-condensed { width: 90% !important; } &lt;/style&gt;
  • 我看不到箭头向下/向上箭头...

标签: r knitr r-markdown plotly ioslides


【解决方案1】:

添加以下样式表:

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

您也可以使其在本地可用,因为即使您在 YAML 标头中使用 self_contained: true,上述解决方案也需要互联网连接。

【讨论】:

  • 它可以在 R 工作室内部工作,但不能在外部工作。 knitr 报告的 HTML 网站中仍然缺少向下箭头/向上箭头。
  • 完美,现在好多了。以及如何减小表格中的字体大小?我应该在
  • 整体字体大小?然后将font-size: 80% 添加到.table-condensed 类选择器...
  • 只有该表中的字体大小。但我明白了。非常感谢您的宝贵时间。
猜你喜欢
  • 2021-02-15
  • 2016-03-02
  • 2023-01-29
  • 2019-12-10
  • 2016-02-28
  • 2022-11-30
  • 1970-01-01
  • 1970-01-01
  • 2021-04-22
相关资源
最近更新 更多