我想使用Shiny中的reactive函数过滤数据。但我没有得到任何输出
我正在尝试使用Shiny中reactive函数内的dplyr包过滤数据,但输出中没有显示任何内容。数据应该按照变量“国家”的级别进行过滤 下面是我使用的代码和数据帧我想使用Shiny中的reactive函数过滤数据。但我没有得到任何输出,shiny,dplyr,shiny-reactivity,Shiny,Dplyr,Shiny Reactivity,我正在尝试使用Shiny中reactive函数内的dplyr包过滤数据,但输出中没有显示任何内容。数据应该按照变量“国家”的级别进行过滤 下面是我使用的代码和数据帧 datos<-data.frame(time=c(rep(c(2001, 2002),3)), values=c(100,200,300,600,700,800), country=c(rep("Uruguay",2),rep("France",2),rep("United States",2))) ui <- fl
datos<-data.frame(time=c(rep(c(2001, 2002),3)), values=c(100,200,300,600,700,800), country=c(rep("Uruguay",2),rep("France",2),rep("United States",2)))
ui <- fluidPage(
selectInput(inputId ="pais", label="Choose a country",
choices =levels(datos$country), selected = "Uruguay"),
plotOutput(outputId ="barplot")
)
server <- function(input, output) {
datos3 <- reactive({
datos%>%
filter(country=="input$pais")
})
output$barplot<-renderPlot({
ggplot(datos3(),aes(x=time,y=values))+geom_bar(stat="Identity")
})
}
shinyApp(ui = ui, server = server)
datos您不需要“input$pais”上的引号
下面是代码,删除了ggplot部分中的额外+
library(shiny)
library(tidyverse)
datos<-data.frame(time=c(rep(c(2001, 2002),3)), values=c(100,200,300,600,700,800), country=c(rep("Uruguay",2),rep("France",2),rep("United States",2)))
ui <- fluidPage(
selectInput(inputId ="pais", label="Choose a country",
choices =levels(datos$country), selected = "Uruguay"),
plotOutput(outputId ="barplot")
)
server <- function(input, output) {
datos3 <- reactive({
datos%>%
filter(country==input$pais) #this bit has been changed
})
output$barplot<-renderPlot({
ggplot(datos3(),aes(x=time,y=values))+geom_bar(stat="Identity")
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(tidyverse)
datos您不需要在“input$PAI”上加引号
下面是代码,删除了ggplot部分中的额外+
library(shiny)
library(tidyverse)
datos<-data.frame(time=c(rep(c(2001, 2002),3)), values=c(100,200,300,600,700,800), country=c(rep("Uruguay",2),rep("France",2),rep("United States",2)))
ui <- fluidPage(
selectInput(inputId ="pais", label="Choose a country",
choices =levels(datos$country), selected = "Uruguay"),
plotOutput(outputId ="barplot")
)
server <- function(input, output) {
datos3 <- reactive({
datos%>%
filter(country==input$pais) #this bit has been changed
})
output$barplot<-renderPlot({
ggplot(datos3(),aes(x=time,y=values))+geom_bar(stat="Identity")
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(tidyverse)
达托斯