在我闪亮的应用程序中,我想更改我想构建的ggplot barChart。 selectinput
应该允许更改月份(请参阅下面的数据集),因此我的情节应该相应地改变。无法在我闪亮的应用程序中使用反应元素
问题:isssue是,我无法使用我的反应函数,甚至只是在ggplot函数中使用简单的input$monthid
。
数据集:
Month Orders
1 Feb 984524
2 Jan 1151303
3 Mar 575000
> dput(b)
structure(list(Month = c("Feb", "Jan", "Mar"), Orders = c(984524L,
1151303L, 575000L)), .Names = c("Month", "Orders"), class = "data.frame", row.names = c(NA,
-3L))
ui.R
library(shiny)
library(shinythemes)
b<-read.csv("b.csv",header=TRUE,sep=",",stringsAsFactors=TRUE)
shinyUI(fluidPage(theme= shinytheme("flatly"),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "monthid", label = "Month",choices = b$Month,selected = b$Month[1])),
mainPanel(plotOutput("plot"))
))
)
server.R
library(shiny)
library(shinythemes)
library(ggplot2)
b<-read.csv("b.csv",header=TRUE,sep=",",stringsAsFactors=TRUE)
shinyServer(function(input, output) {
#making a reactive object
m<-reactive ({
as.character(input$monthid)
})
output$plot<- renderPlot({
#probably I am making a subset error in x inside aes parameter
ggplot(data = b, aes(x = b[,m()] ,y = b$Orders)) + geom_bar(stat="identity")
})
})
它说:'错误:未定义列selected' – Shoaibkhanz 2015-03-27 12:34:02
我相信这个问题是我的'$输入'monthid是行而不是列。 – Shoaibkhanz 2015-03-27 12:37:24
我创建了2个反应元素,它可以工作,但情节不是按比例缩放的,你可以重现这一点,并尝试'm <-reactive(c <-as.data.frame(b [b $ Month == input $ monthid, ]) ç }) ORD <反应性({ 或<-m() 或<-as.data.frame(或[2]) }) 输出$情节< - renderPlot( { #可能我正在做一个子集错误在x中的aes参数 ggplot(data = b,aes_string(x = m(),y = ord()))+ geom_bar(stat =“identity”)' – Shoaibkhanz 2015-03-27 12:47:59