在我閃亮的應用程序中,我想更改我想構建的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