【发布时间】:2015-08-04 09:12:40
【问题描述】:
在下面闪亮的应用程序中,我想使用来自reactive 的数据框dt 称为数据,在renderPlot 中。
我通过ggplot(dt, aes(x, y)) + geom_point() 和ggplot(data(), aes(x, y)) + geom_point() 尝试了不同的方法
我只是不知道如何将数据帧从一个反应部分传输到另一个。
编辑
我想我通过使用找到了解决方案:ggplot(data()$dt, aes(x,y) + ... 但现在问题似乎出在dplyr 包中的filter 中。
有什么建议吗?
服务器:
# server
library(dplyr)
library(shiny)
library(ggplot2)
df <- data.frame(x = rnorm(100), y = rnorm(100)) %>%
mutate(id = ntile(x, 4))
shinyServer(function(input, output) {
data <- reactive({
dt <- dt %>%
filter(id == input$id)
})
output$plot <- renderPlot({
ggplot(dt, aes(x,y) +
geom_point()
})
})
用户界面:
## ui
library(shiny)
library(ggplot2)
shinyUI(fluidPage(
sidebarPanel(width = 2,
selectInput("id",
"Select ID:",
c(1:4))
),
mainPanel(width = 10,
plotOutput("plot")
)
))
【问题讨论】: