我可以使用静态值show_hide
隐藏导航栏页面,但无法弄清楚如何使用有效值r_show_hide()
进行导航。我也尝试过使用isolate(ifelse...)
,然后使用r_show_hide
(无括号)以及reactiveVal()
都无效。
还有一个多余的">
显示出来。任何帮助将不胜感激。
更新: 我创建了一个问题https://github.com/rstudio/flexdashboard/issues/229
---
title: "-"
output: flexdashboard::flex_dashboard
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
show_hide <- "show" # "hidden"
r_show_hide <- reactive(ifelse(session$clientData$url_hostname == "127.0.0.1", "hidden", "show"))
```
Does work {.`r show_hide`}
=============================
### Should be `r show_hide`
Doesn't work {.`r reactive(r_show_hide())`}
===============================
### Should be `r renderText(r_show_hide())`
答案 0 :(得分:1)
好吧,这花了我一段时间。
基本问题是,flexdashboard导航栏中大括号中的r个块在非反应性上下文中进行评估,而构建每个页面内容的r个块在反应性上下文中进行评估。因此,您不能使用诸如r_show_hide()
之类的反应式来触发导航栏页面的隐藏/显示参数,但是可以在页面内的r_show_hide()
函数中使用renderText()
。 >
因此,实际的问题是,如何从非反应性上下文访问反应性值。答案为isolate()
,并解释为here。
下面我提供一个使用您的代码的示例。
---
title: "-"
output: flexdashboard::flex_dashboard
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
show_hide <- "show" # "hidden"
r_show_hide <- reactive(ifelse(session$clientData$url_hostname == "127.0.0.1", "hidden", "show"))
```
Does work {.`r show_hide`}
=============================
### Should be `r show_hide`
Doesn't work {.`r isolate(r_show_hide())`}
===============================
### Should be `r renderText(r_show_hide())`