[英]R Shiny slider problems
Hi I'm trying to set up a Shiny app, but I'm having trouble accessing data from a slider that I've set up. 嗨,我正在尝试设置一个Shiny应用程序,但是从设置好的滑块访问数据时遇到了麻烦。 For some reason,
input$slider1[1]
is not an integer, so I can't compare with with Num_adults
, which is an integer. 由于某些原因,
input$slider1[1]
不是整数,因此我无法与Num_adults
进行比较,后者是一个整数。
This is the code where I try to access the slider 这是我尝试访问滑块的代码
server<-function(input,output){
output$bar1 <- renderPlot({
AllData1 <- AllData[!is.na(AllData$Num_adults),]
AllData1$Num_adults <- as.numeric(AllData1$Num_adults)
filter(AllData1$Num_adults >= input$slider1[1], AllData1$Num_adults <= input$slider1[2])
ggplot(AllData1, aes(x=AllData1$Num_adults) + geom_histogram)
})
}
and this is the code where I set up the slider. 这是我设置滑块的代码。 Any help is appreciated.
任何帮助表示赞赏。 Thanks!
谢谢!
ui<-fluidPage(
titlePanel(a(span("Data on Recipients of MSF.", style="color:purple"))),
sidebarLayout(
sidebarPanel(
helpText("For the first graphic, you can..."),
sliderInput(inputId = "slider1",
label = h3("Number of adults in a household"),
min = 0, max = 8, value = c(1,2))),
mainPanel(plotOutput("bar1"))
))
shinyApp(ui=ui, server=server)
Modifying your server code to this should work (although I can't test without data): 将服务器代码修改为此应该可以(尽管没有数据我无法测试):
library(dplyr)
server<-function(input,output){
output$bar1 <- renderPlot({
AllData1 <- AllData[!is.na(AllData$Num_adults), ]
AllData1 <- filter(AllData1, Num_adults >= input$slider1[1] &
Num_adults <= input$slider1[2])
ggplot(AllData1, aes(x = Num_adults)) + geom_histogram()
})
}
You can simplify the NA
filtering by incorporating into the filter
call, but that is not essential. 您可以通过合并到
filter
调用中来简化NA
过滤,但这不是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.