Conditional reactive logic shiny based flexdashboard

冷暖自知 提交于 2019-12-03 07:21:58

To get different kind of output depending on the length of the inputed character string you can do following:

1) Create a dynamic output uiOutput,

2) In the reactive environment renderUI, depending on the input, choose kind of the output.

3) Render the output

---
title: "Citation Extraction"
output: 
flexdashboard::flex_dashboard:
vertical_layout: scroll  
orientation: rows
social: menu
source_code: embed
runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
```


Sidebar {.sidebar}
=====================================

```{r, echo = F}
textInput("txt", "What's up?:", value = "")
```

Page 1
=====================================

### Chart A

```{r, echo = F}
uiOutput("dynamic")

output$dynamic <- renderUI({ 
  if (nchar(input$txt) > 20) plotOutput("plot")
  else textOutput("text")
})

output$plot <- renderPlot({ plot(1:10, 1:10) })
output$text <- renderText({ input$txt })

```
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!