我正在为不同员工的年度绩效评估创建一个ShinyApp,并希望根据选择的输入显示一个或多个员工(W)的绩效(salespermonth)。但是,当在sidebarPanel中选择了多个"W“时,我遇到了更改相同"W”的值的问题。有人知道为什么吗?
不知何故,data.b
的反应功能似乎有问题,更准确地说,是ID==input$ID
的部分。
data.frame
示例(ID从1到10):
ID Calendartime timewithfirm salespermonth cumm.sales
1 1 2006-01-01 3 800 800
2 1 2006-02-01 3 300 1100
3 1 2006-03-01 3 150 1250
4 1 2006-04-01 3 200 1450
5 1 2006-05-01 3 350 1800
6 1 2006-06-01 3 100 1900
ui.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel(title=h1("Worker Performance Assessment", align="center")),
sidebarPanel(
uiOutput("chooseW"),
dateRangeInput("daterange", label = h3("Date range"),start = "2006-01-01",end = "2006-12-01",format = "yyyy/mm/dd", separator="-"),
submitButton(text="Update!")
) ,
mainPanel(
plotOutput("salesplot")
)
)
)
。R server.R
library(shiny)
library(ggplot2)
library(scales) # for formatting date scales in ggplot
shinyServer(function(input, output) {
output$chooseW <- renderUI({
IDs<- dataframe$ID
selectInput("ID", label=h3("Choose a Worker"), IDs, 1 , multiple = TRUE)
})
# reactive function for plot
data.b = reactive({
b= subset(dataframe,Calendartime %in% (input$daterange[1]:input$daterange[2]) & ID == input$ID)
return(b)
})
output$salesplot <- renderPlot({
cc<- data.b()
q= ggplot(cc, aes(x=Calendartime,y=salespermonth, group=ID, colour=ID)) +
geom_line() +scale_x_date(breaks = date_breaks("1 month"),labels = date_format("%b"))
print(q)
})
})
发布于 2015-04-21 18:50:38
你是正确的。问题出在ID == input$ID
的问题上。你只需要在server.R的子集成行中将其更改为ID %in% input$ID
,问题就会迎刃而解。这里的要点是,如果您有多个选择,则input$ID
不只是一个值,而是一个长度大于1的向量。
https://stackoverflow.com/questions/29660953
复制相似问题