我正在嘗試使直方圖對dateInputRange函數作出反應。我有我的應用程序已經工作,只有一個年齡滑塊輸出到直方圖,還有一個表格下方的結果也。我將dateInputRange添加到了我的代碼中,並根據我想要過濾的源數據中的列(基於日期)過濾了輸出,並且應用程序仍會啓動,但直方圖不再繪製。 renderTable仍然對滑塊輸入作出反應,但對於直方圖,我只是得到一個空白的灰色圖。R Shiny dateInputRange函數中斷直方圖
當我啓動應用程序,控制檯給我這個消息:
「警告在==.default
(C(」 2016" 年10月11日, 「2016年10月16日」,「11月22日/ 2016" , 「2016年11月21日」,: 更長對象長度不短對象長度的倍數」
代碼如下:
ui <- fluidPage(
titlePanel("ED Admissions"),
sidebarLayout(
sidebarPanel(
sliderInput("AgeInput","Age",min = 3, max = 125, c(3,65)),
dateRangeInput("DateInput", "Date")
),
mainPanel(
plotOutput("AgePlot"),
br(), br(),
tableOutput("ClientTable")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$AgePlot <- renderPlot({
filtered <-
edadmits %>%
##filtering is by variables in the dataset
filter(Client_AGE >= input$AgeInput[1],
Client_AGE <= input$AgeInput[2],
Discharge_Claim_Start_Date == input$DateInput
)
ggplot(filtered, aes(Client_AGE))+
geom_histogram()
})
output$ClientTable <- renderTable({
filtered <-
edadmits %>%
filter(Client_AGE >= input$AgeInput[1],
Client_AGE <= input$AgeInput[2])
filtered
})
}
shinyApp(ui = ui, server = server)
這裏是一個重複的例子:
library(shiny)
library(ggplot2)
library(dplyr)
Name <- c("Person 1","Person 2","Person 3","Person 4","Person 5","Person 6","Person 7","Person 8",
"Person 9","Person 10","Person 11","Person 12", "Person 13","Person 14","Person 15",
"Person 16","Person 17","Person 18","Person 19","Person 20")
Diagnosis <- sample(1:10, 20, replace=TRUE)
Discharge.Date <- sample(seq(as.Date('2016/12/01'), as.Date('2016/12/31'), by="day"), 20)
Age <- sample(1:125, 20)
edadmits <- data.frame(Name, Diagnosis, Discharge.Date, Age)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("ED Admissions, 12.1.16-12.31.16"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("AgeInput","Age",min = 3, max = 125, c(3,65)),
dateRangeInput("DateInput", "Date", start= "2016-12-01", end= "2016-12-31",
min= "2016-12-01", max = "2016-12-31")
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("AgePlot"),
br(), br(),
tableOutput("ClientTable")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$AgePlot <- renderPlot({
filtered <-
edadmits %>%
##filtering is by variables in the dataset
filter(Age >= input$AgeInput[1],
Age <= input$AgeInput[2],
Discharge.Date >= input$DateInput[1],
Discharge.Date <= input$DateInput[2]
)
ggplot(filtered, aes(Age))+
geom_histogram()
})
output$ClientTable <- renderTable({
filtered <-
edadmits %>%
##filtering is by variables in the dataset
filter(Age >= input$AgeInput[1],
Age <= input$AgeInput[2],
Discharge.Date >= input$DateInput[1],
Discharge.Date <= input$DateInput[2])
filtered
})
}
# Run the application
shinyApp(ui = ui, server = server)
替換'Discharge_Claim_Start_Date ==輸入$ DateInput'用'Discharge_Claim_Start_Date> =輸入$ DateInput [1],Discharge_Claim_Start_Date <= $輸入DateInput [2]' – HubertL
謝謝,但這似乎不起作用,情節仍然沒有渲染。 – Yallweh
控制檯中的錯誤消息確實消失了您的建議更改,但應用程序的行爲相同。將工作在一個可重複的例子。 – Yallweh