我正在编写一个新的Shiny应用程序,我想使用dplyr命令进行数据操作。我希望Shiny能够打印一些图形,这些图形将一些聚合数据作为输入。例如,一个用户可能希望看到图表均值与simi.mean,周数固定为0,而另一个用户希望看到均值vs simi.mean,其中rel固定为1。
我有这个用于ui.R:
shinyUI(pageWithSidebar(
headerPanel(' '),
sidebarPanel(
selectInput('zcol', 'Variable to be fixed', names(taxi.agg[,-c(1,4,5,7,8,9,10,11)])),
conditionalPanel(condition = "input.zcol == 'week'",
selectInput("levels", "Levels",c(0,1),selected = 1
)),
conditionalPanel(condition = "input.zcol == 'tollfree'",
selectInput("levels", "Levels",c(0,1),selected = 1
)),
conditionalPanel(condition = "input.zcol == 'rel'",
selectInput("levels", "Levels",c(1,4),selected = 1
)),
conditionalPanel(condition = "input.zcol == 'source'",
selectInput("levels", "Levels",c(1,2),selected = 1
)),
conditionalPanel(condition = "input.zcol == 'hour'",
sliderInput("levels", "Levels",value = 18,
min = 0,
max = 23
))
),
mainPanel(
plotOutput('plot1')
)
))
这对于server.R:
taxi.agg <- read.delim("taxi", header=T,colClasses =c(rep("factor",7),rep("numeric",5),rep("factor",2)) )
shinyServer(function(input, output, session) {
output$selectedData <- renderTable({
data_stats <- eval(substitute(taxi.agg %>% group_by(simi.mean,col) %>% summarise(mean = mean(prop.conv)) %>%
filter(col==lvl) %>% select(simi.mean,mean),
list(col=as.symbol(input$zcol),
lvl=as.symbol(input$levels))))
})
output$plot1 <- renderPlot({
plot(selectedData())
})
})
在Shiny之外,命令:
plot(data_stats)
给出了我想要的答案。但在Shiny我得到:
情节错误(selectedData()):找不到函数&#34; selectedData&#34;
我想我在dplyr构造表上传递参数可能会出错。 有任何想法吗?谢谢你的帮助!