Как использовать выпадающее меню для отображения разных таблиц?

#r #r-markdown #dt

#r #r-уценка #dt #r-markdown

Вопрос:

У меня есть 3 разные таблицы

 May_Sales <- data.frame(State  = c("New York", "New Jersey", "Texas","New Mexico","California",
                               "Kansas","Florida","Alaska","Montana", "Maine"),
                    
                    ManagerName = c("Chip","Kelly","Steve","Young","Troy",
                                    "Aikman", "Chad","Pennington","Mike","Vick"),
                    
                    Units = c(455,453,125,135,135,568,451,125,215,314),
                    
                    Sales = c("20000","12530","51110","54110","65000",
                                  "58220","54612","45102","45896","12510"),
                    
                    Target_Sales = c("20000","20000","55000","50000","65000",
                                        "58000","55000","45000","45000","13000"))

June_Sales <- data.frame(State  = c("New York", "New Jersey", "Texas","New Mexico","California",
                               "Kansas","Florida","Alaska","Montana", "Maine"),

                    ManagerName = c("Chip","Kelly","Steve","Young","Troy",
                                    "Aikman", "Chad","Pennington","Mike","Vick"),

                    Units = c(460,463,165,139,165,668,421,125,205,316),

                    Sales = c("21000","13530","51010","54410","63000",
                                  "56220","57612","42602","43696","12160"),

                    Target_Sales = c("25000","15000","55000","55000","65000",
                                        "58000","55000","47000","45000","13000"))

July_Sales <-  data.frame(State  = c("New York", "New Jersey", "Texas","New Mexico","California",
                               "Kansas","Florida","Alaska","Montana", "Maine"),

                    ManagerName = c("Chip","Kelly","Steve","Young","Troy",
                                    "Aikman", "Chad","Pennington","Mike","Vick"),

                    Units = c(405,353,325,155,235,560,401,125,215,314),

                    Sales = c("20200","16210","51310","56110","65500",
                                  "58225","54602","45602","45806","12410"),

                    Target_Sales = c("25000","22000","55000","50000","65000",
                                        "60000","55000","35000","40000","10000"))







  

Что я обычно делаю, я просто помещаю каждую таблицу в datatable() и помещаю ее в документ Rmarkdown, но я бы предпочел, чтобы все таблицы были в одном разделе, и просто выбирал, какую из них я хотел бы видеть.

 library(DT)
datatable(May_Sales)
  

Но есть ли способ (с или без DT) получить выпадающее меню, чтобы выбрать, какой месяц продаж я хочу видеть?

Комментарии:

1. Здесь bsselectR может помочь -package . Некоторые примеры см. На GitHub или здесь .

Ответ №1:

Вы можете использовать .tabset-dropdown функцию:

 ```{r}
library(DT)

July_DT <- datatable(July_Sales)
June_DT <- datatable(June_Sales)
May_DT <- datatable(May_Sales)
```

# Sales {.tabset .tabset-dropdown}

 ## May Sales 

```{r ,echo = FALSE}
May_DT    
```
## June Sales

```{r ,echo = FALSE}
June_DT
```


## July Sales 

```{r ,echo = FALSE}
July_DT
```
  

введите описание изображения здесь