【发布时间】:2018-07-08 04:38:30
【问题描述】:
对于我的生活,我无法解决这个问题,我在 R Studio 中使用 Flexdashboard,并且我有两个表。我想要做的是切换通过 selectInput 显示的表格。我的 selectInput 目前是:
```{r setup, include=FALSE}
library(flexdashboard)
library(DT)
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(png)
library(grid)
library(kableExtra)
library(knitr)
```
```{r, echo = FALSE}
selectInput("platform", label = "Select Platform:",
choices = c("MB","DS"))
```
MB_Val 和 DS_Val 的 csv 文件可以从这里提取:
DS_Val here
MB_Val here
我的两张图表如下:
MB_Val %>%
mutate(Val = cell_spec(
format(round(Val, 2), nsmall = 2), "html", color = "white", bold = T,
background = "#7FC64F")) %>%
mutate(ValFm = cell_spec(
format(round(ValFm, 2), nsmall = 2), "html", color = "white", bold = T,
background = "#7FC64F")) %>%
kable("html", escape = F, align = c('l',rep('c',ncol(MB_Val)-1))) %>%
kable_styling(bootstrap_options = c("striped", "condensed","hover")) %>%
scroll_box()
和
DS_Val %>%
mutate(Val = cell_spec(
format(round(Val, 2), nsmall = 2), "html", color = "white", bold = T,
background = "#7FC64F")) %>%
mutate(ValFm = cell_spec(
format(round(ValFm, 2), nsmall = 2), "html", color = "white", bold = T,
background = "#7FC64F")) %>%
kable("html", escape = F,align = c('l',rep('c',ncol(DS_Val)-1))) %>%
kable_styling(bootstrap_options = c("striped", "condensed","hover")) %>%
scroll_box(height = "200px")
我尝试了很多东西,最近的是这个。如果可能的话,我也希望能够保留所有格式。
```{r, echo = FALSE}
div(renderTable({ifelse(input$platform %in% c("MB"),MB_Val,DS_Val)}),
style = "font-size:80%")
```
【问题讨论】:
-
请提供一个可重现的例子。 stackoverflow.com/questions/5963269/…
-
已添加指向 csv 文件的链接以允许重新制作。
标签: r shiny flexdashboard