刚翻到一个SO上的帖子,里面的思路是用一段 JS 代码获取Tab页的位置,根据位置判断要不要渲染结果,接近了我想要的效果(按页面是否激活加载数据),可碰到很多段落都有 Tab 页的时候,就不合适了,最好根据 Tab 页的Heading identifiers 是否激活来确认,后面的我就不知道怎么搞了?
下面是一个示例,是目前的进展状态
---
title: "Untitled"
runtime: shiny
output:
flexdashboard::flex_dashboard:
theme: bootstrap
orientation: rows
vertical_layout: scroll
mathjax: null
---
```{r setup, include=FALSE}
library(shiny)
library(flexdashboard)
```
<script>
$("body").on("shown.bs.tab", "a[data-toggle='tab']", function(e) {
Shiny.setInputValue("active_tab", $(e.target).parent().index());
})
</script>
```{r}
GLOBAL_VALUE <- reactive({
list(tab_status = input$active_tab)
})
```
Row {.tabset data-height=350}
-----------------------------------------------------------------------
### Chart A
```{r}
renderPrint({
GLOBAL_VALUE()[["tab_status"]]
})
```
### Chart A
```{r}
renderPrint({
GLOBAL_VALUE()[["tab_status"]]
})
```
Row {.tabset data-height=350}
-----------------------------------------------------------------------
### Chart B {#chartb}
```{r}
renderPrint({
GLOBAL_VALUE()[["tab_status"]]
})
```
### Chart C
```{r}
renderPrint({
GLOBAL_VALUE()[["tab_status"]]
})
```
### Chart D
```{r}
renderPrint({
GLOBAL_VALUE()[["tab_status"]]
})
```
示例效果,我录了个屏,帮助大家理解我的意思
https://user-images.githubusercontent.com/12031874/126319704-b40bed48-4cf5-4a84-a584-a94925460fa3.mov