我尝试使用详细选项的Markdown文档(即显示或不显示页面代码,以避免害怕人:D),具体取决于用户的选择(基本上是单选按钮小部件)。
因此我执行了以下代码:
---
title: "Hello"
author: "Charlotte S."
date: "8 février 2018"
output: html_document
runtime: shiny
---
```{r}
radioButtons("verbose", label = "",
choices = c("Yes", "No"),
selected = "No")
verboseAction <- reactive({
if(!is.null(input$verbose)){
if(input$verbose == "Yes"){
TRUE
} else {
FALSE
}
} else {
FALSE
}
})
output$print <- renderText({
verboseAction()
})
```
Here `r textOutput("print")`
```{r echo = verboseAction()}
2+2
```
R的答案:&#34;没有被动上下文的情况下不允许进行操作
好的没问题,我做了:
---
title: "Hello"
author: "Charlotte S."
date: "8 février 2018"
output: html_document
runtime: shiny
---
```{r}
radioButtons("verbose", label = "",
choices = c("Yes", "No"),
selected = "No")
verboseAction <- reactive({
if(!is.null(input$verbose)){
if(input$verbose == "Yes"){
TRUE
} else {
FALSE
}
} else {
FALSE
}
})
output$print <- renderText({
verboseAction()
})
```
Here `r textOutput("print")`
```{r echo = observe(verboseAction())}
2+2
```
不能正常工作
---
title: "Hello"
author: "Charlotte S."
date: "8 février 2018"
output: html_document
runtime: shiny
---
```{r}
radioButtons("verbose", label = "",
choices = c("Yes", "No"),
selected = "No")
verboseAction <- reactive({
if(!is.null(input$verbose)){
if(input$verbose == "Yes"){
TRUE
} else {
FALSE
}
} else {
FALSE
}
})
output$print <- renderText({
verboseAction()
})
```
Here `r textOutput("print")`
```{r global_options, include=FALSE}
option <- reactive({
if(!is.null(verboseAction())){
opts_chunk$set(fig.width=12, fig.height=8, fig.path='Figs/',
echo=verboseAction(), warning=FALSE, message=FALSE)
}
})
```
```{r}
2+2
```
Nope nope nope
你知道怎么做吗?我在{r}中找不到任何具有反应值的例子,我甚至不确定它是否可能......(我也尝试过使用tcltk,但因为没有反应性而更糟)...
提前致谢,祝你有个美好的一天!
茶
答案 0 :(得分:2)
您希望在Yet Another Markup Language code_folding
中声明(YAML) header选项。
您可以将默认代码折叠设置为自动隐藏(code_folding: hide
)或显示(code_folding: show
)用户的代码块。
---
title: "Hello"
author: "Charlotte S."
date: "8 février 2018"
output:
html_document:
code_folding: hide
runtime: shiny
---
```{r}
radioButtons("verbose", label = "",
choices = c("Yes", "No"),
selected = "No")
verboseAction <- reactive({
if(!is.null(input$verbose)){
if(input$verbose == "Yes"){
TRUE
} else {
FALSE
}
} else {
FALSE
}
})
output$print <- renderText({
verboseAction()
})
```
Here `r textOutput("print")`
```{r global_options, include=FALSE}
option <- reactive({
if(!is.null(verboseAction())){
opts_chunk$set(fig.width=12, fig.height=8, fig.path='Figs/',
echo=verboseAction(), warning=FALSE, message=FALSE)
}
})
```
```{r}
2+2
```