2017-08-17 85 views
0

我建立一個基於光澤,flexdashboard,我有渲染閃亮flexdashboard - 劇情不渲染

一個問題這是我的數據框:

structure(list(from_id = c("385588434812408", "385588434812408", 
"385588434812408", "385588434812408", "385588434812408", "385588434812408" 
), from_name = c("Стопанска банка - На ваша страна", 
"Стопанска банка - На ваша страна", 
"Стопанска банка - На ваша страна", 
"Стопанска банка - На ваша страна", 
"Стопанска банка - На ваша страна", 
"Стопанска банка - На ваша страна"), 
    year = c(2017L, 2017L, 2017L, 2017L, 2017L, 2017L), month = c(8L, 
    8L, 8L, 8L, 8L, 8L), bank = c("stopanska", "stopanska", "stopanska", 
    "stopanska", "stopanska", "stopanska"), likes_count = c(17L, 
    20L, 366L, 240L, 50L, 7L)), .Names = c("from_id", "from_name", 
"year", "month", "bank", "likes_count"), class = c("data.table", 
"data.frame"), row.names = c(NA, -6L), .internal.selfref = <pointer: 0x2fae898>) 

這是我的代碼:

Column {.sidebar} 
----------------------------------------------------------------------- 

```{r} 
selectInput("bank_id", label = "Select a bank:", 
      df$bank, selected = "stopanska") 

selectInput('x', 'Year', names(df)) 
selectInput('y', 'Likes', names(df)) 
``` 

Column 
----------------------------------------------------------------------- 

```{r} 

dataset <- reactive({ 
    df[input$bank_id, ] 

    }) 


renderPlot({ 
    p <- ggplot(dataset(), aes_string(x=input$x, y=input$y)) + geom_bar() 

    print(p) 
}) 

    ``` 

我從df獲得了側邊欄的值,但情節並未呈現。任何暗示爲什麼?

我確定它是一個非常基本的問題,但我是Shiny的新手。

回答

0

爲了演示渲染,您的代碼可能會沿着下面的代碼行。請注意,我更改了輸入(xy),原因在我看來不可用。

--- 
title: "bank likes" 
output: 
    flexdashboard::flex_dashboard: 
    orientation: columns 
    vertical_layout: fill 
--- 

```{r setup, include=FALSE} 
library(flexdashboard) 
library(ggplot2) 
library(shiny) 
df<-read.table(text="from_id      from_name year month  bank likes_count 
385588434812408 Стопанска_банка_На_ваша_страна 2017  8 stopanska   17 
385588434812408 Стопанска_банка_На_ваша_страна 2017  8 stopanska   20 
385588434812408 Стопанска_банка_На_ваша_страна 2017  8 stopanska   366 
385588434812408 Стопанска_банка_На_ваша_страна 2017  8 stopanska   240 
385588434812408 Стопанска_банка_На_ваша_страна 2017  8 stopanska   50 
385588434812408 Стопанска_банка_На_ваша_страна 2017  8 stopanska   7", stringsAsFactors=F, header=T) 
``` 

Column {.sidebar} 
----------------------------------------------------------------------- 

    ```{r} 
selectInput("bank_id", label = "Select a bank:", 
     df$bank, selected = "stopanska") 

selectInput('x', 'Year', choices=unique(df$year)) 
selectInput('y', 'Likes', choices=unique(df$likes_count)) 
``` 

Column 
----------------------------------------------------------------------- 

    ```{r} 

dataset <- reactive({ 
df[input$bank_id, ] 

}) 


renderPlot({ 
p <- ggplot(dataset(), aes(x=input$x, y=input$y)) + 
geom_bar(stat="identity") 

print(p) 
}) 

```