df1 <-
structure(
list(
`long name 1` = c(NA, 18L, NA, 24L, 21L, NA, NA,NA, NA, NA),
`long name 2` = c(NA, 24L, NA, 35L, 23L, NA, NA,NA, NA, 25L)
), class = c("tbl_df", "data.frame"),
row.names = c(NA,-10L), .Names = c("long name 1", "long name 2")
)
server <- function(input, output) {
output$txt1 <- renderText({
df1 %>% summarise(y1 = mean(input$select,na.rm = T)) %>%
as.character()
})
}
ui <- fluidPage(sidebarLayout(sidebarPanel(
width = 3,
selectInput(
"select", label = h3("Variable"),
choices = list("long name 1" = "long name 1",
"long name 2" = "long name 2"),
selected = 1
)
),
mainPanel(h3(textOutput(
"txt1"
)))))
shinyApp(ui = ui, server = server)
The only solution that I can think is to use a series of if statements instead of using input$select directly in summarise. Any suggestions?