Rshiny:使用反应函数中的数据绘制反应图
我正在使用flexdashboard在Rmarkdown文件中制作一个闪亮的应用程序,但我无法使用反应函数中的数据绘制ggplot 以下是步骤/要素:Rshiny:使用反应函数中的数据绘制反应图,r,ggplot2,shiny,R,Ggplot2,Shiny,我正在使用flexdashboard在Rmarkdown文件中制作一个闪亮的应用程序,但我无法使用反应函数中的数据绘制ggplot 以下是步骤/要素: 从询问日期的单选按钮获取输入,然后打印答案 (检查他是否反应良好)->有效 反应函数读取相关csv文件(基于日期) 并打印它的内容(检查)->作品 使用csv文件->的内容生成的ggplot无效 当我使用renderPlot()使用非反应性数据集(我加载了一个)生成ggplot时,我得到了正确的结果,因此ggplot部分很好 这和反应性渲染图的组
---
title: "Tests plot"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(ggplot2)
```
Input {.sidebar}
======================================
```{r}
radioButtons("countdate",h3("Datum"), c("01-12-2017"="T1","06-12-2017"="T2","24-12-2017"="T3"))
```
Data
======================================
Column
-----------------------------------------------------------------------
### Date
```{r}
reactive({ #OK
input$countdate
})
```
Column
-----------------------------------------------------------------------
### Data
```{r}
fake2 <- reactive({read.csv2(paste(input$countdate, ".csv", sep = ""))})
fake2 #OK
```
Column
-----------------------------------------------------------------------
### Plot
```{r}
ggplot1 <- reactive({
renderPlot({ggplot(fake2, aes(Rij, Plant)) +
xlim(0,40) +
ylim(0,50) +
coord_equal() +
geom_raster(aes(fill=Wtot)) +
scale_fill_gradient(low="yellow", high="red")
})
})
ggplot1
```
我的数据如下所示:
Vplaat;Rij;Plant;Mtot;Wtot
A;4;10;2;20
B;4;46;5;35
C;9;5;1;14
D;9;30;0;42
E;11;17;8;85
...
多亏了一位名叫Florian的开发者,我才得到了答案,但不幸的是,他删除了他的评论 他告诉我在处理被动内容时需要使用x()而不是x,在我的例子中:
ggplot(fake2()…
而不是ggplot(fake2…
这一开始并不奏效,但让我走上了正轨
除此之外,我还必须删除renderPlot函数周围的reactive({})
,然后它才能工作
谢谢你的帮助,弗洛里安
新代码:
renderPlot({
ggplot(fake2(), aes(Rij, Plant)) +
xlim(0,40) + #rijen
ylim(0,50) + #planten
coord_equal() +
geom_raster(aes(fill=Wtot)) +
scale_fill_gradient(low="yellow", high="red")
})
reactive是函数。尝试使用
fake2()
是否有效?是的,就是这样。另一个人已经回答了这个问题,但因为我还需要删除reactive()(他没有告诉我,可能忘了在代码中删除它)它不起作用。问题解决了,谢谢你们!嗨,Tingolfin,很抱歉删除了我的答案,我对这种降价风格的闪亮应用没有太多经验,所以我认为我的答案完全是错的。很高兴你们能够解决自己的问题!
renderPlot({
ggplot(fake2(), aes(Rij, Plant)) +
xlim(0,40) + #rijen
ylim(0,50) + #planten
coord_equal() +
geom_raster(aes(fill=Wtot)) +
scale_fill_gradient(low="yellow", high="red")
})