[英]Shiny flexdashboard - plot not rendering
我正在構建一個基於光澤的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的新手。
為了演示渲染,您的代碼可以遵循以下幾行。 請注意,我更改了輸入( x
和y
),因為我認為原始輸入不可用。
---
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)
})
```
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.