2016-04-22 4 views
9

何らかの入力に基づいてレンダリング(renderPlot)または別のタイプ(renderText)のどちらかをcontiditonallyしようとしています。ここに私が試したものです:条件付きリアクションロジックシャイニーベースのフレックスダッシュボード

--- 
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} 
textInput("txt", "What's up?:") 
``` 

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

### Chart A 

```{r} 
urtxt <- reactive({input$txt}) 

if (nchar(urtxt()) > 20){ 
    renderPlot({plot(1:10, 1:10)}) 
} else { 
    renderPrint({ 
     urtxt() 
    }) 
} 
``` 

しかし、それは述べている:

enter image description here

だから私は、関数にreactiveリターンを返すの条件結果として生じる周りの反応を追加してみました。

reactive({ 
    if (nchar(urtxt()) > 20){ 
    renderPlot({plot(1:10, 1:10)}) 
} else { 
    renderPrint({ 
     urtxt() 
    }) 
} 
}) 

どのように条件付きリアクティブロジックを使用できますか?応じて反応性環境renderUIでダイナミック出力uiOutputを作成

1)、

2)、:あなたは次の操作を行うことができますinputed文字列の長さに応じて、出力の異なる種類を取得するには

+0

をレンダリングします。質問品質にかかわらず誰かが私のすべてを投票しているようだ。ダウンフォートの本当の理由がある場合は、私が改善できるように共有してください。 –

+2

最近、多くの匿名ダウンワード投票があるようですが、そのほとんどは無作為の重複のためです。これははるかに躍動的であり、比較的新しい用途から良い答えを引き出すという利点がありました。両方にあなたに誇り。 –

答えて

9

入力、出力の種類を選択します。

3)ダウン投票を理解しようとすると、出力

--- 
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 }) 

``` 
+1

完璧なおかげで、私も多くのことを学びました。素晴らしい説明。 –