Reputation: 119
I'm trying to create a reactive valuebox based on a filter sorting out towns from two dataframes.
Choosing a map from the dropdown menu should display the variable "test_num" in the valueBox. Here is what I've done so far:
data2 <- data.frame(Origine= c('NY','NY','NY','NY','NY','PL','PL', 'PL','PL','PL','AS','AS','AS','AS','AS','RY','RY','RY','RY','RY', 'JK', 'JK', 'JK', 'JK', 'JK'), Annee=c('2000', '2002', '2004', '2006', '2008', '2000', '2002', '2004', '2006', '2008','2000', '2002', '2004', '2006', '2008','2000', '2002', '2004', '2006', '2008','2000', '2002', '2004', '2006', '2008'),
var2 = c(12,20,10,8,14, 12,20,10,8,14,12,20,10,8,14,12,20,10,8,14,12,20,10,3,5))
data <- data.frame(Origine= c('NY','PL','AS','RY','JK'), var1=c('a', 'b', 'c', 'd', 'e'),
test_num = c(1,1,0,0,1))
ui <-basicPage(selectInput(inputId = "Origine",
label = h1("Town"),
choices = unique(data2$Origine),
selected = "NY"),
box(width = NULL,
valueBoxOutput("variable1"),
)
)
test <- data
server <- function(input, output) {
output$variable1 <-renderValueBox({
test %>%
filter(Origine == input$Origine
)
valueBox((test$test_num), "test number:", icon = icon("list"), color = "purple")
})
}
shinyApp(ui, server)
Upvotes: 0
Views: 262
Reputation: 36
You have to filter the dataframe inside the output and put it in a new dataframe. And then call it in the valueBox.
server <- function(input, output) {
output$variable1 <-renderValueBox({
test <- data %>% filter(Origine == input$Origine)
valueBox(paste0(test$test_num), "test number:", icon = icon("list"), color = "purple")
})
Upvotes: 2