I am trying to reactively change my radio buttons based on the UI inputs of my RShiny.
But currently my radio button is showing the column name instead of the unique values inside the column. I tried the code on base R and I am sure the function returns the unique values of the column. Would like to seek help on why is this happening. I do not think there is issue with calling the datatable because it has successfully print all the columns inside my selectInput.
UI
library(shiny)
library (igraph)
library (tidygraph)
library (ggraph)
library (tmap)
library (tidyverse)
library (sf)
recreation_visit <- readRDS("data/recreation_visit.rds")
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Trial"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
uiOutput("socialFilter"),
uiOutput("socialFilterfill"),
uiOutput("filter2")
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
my server code
server <- function(input, output, session) {
statsplot1 <- reactive ({
new <- recreation_visit %>%
group_by(!!! rlang::syms(input$socialfilter)) %>%
summarise(Visitcount = n())
new
})
statsplot2 <- reactive ({
new1 <- recreation_visit %>%
group_by(!! rlang::syms(input$socialfilter), !! rlang::syms(input$socialfiltergroup)) %>%
summarise(Visitcount = n())
new1
})
output$socialFilter <- renderUI({
selectInput("socialfilter","Choose X Axis Variable for Statisitical Plot:", choices=colnames(recreation_visit)[names(recreation_visit) %in% c("Visitcount", "Participant Id") == FALSE])
})
output$socialFilterfill <- renderUI({
req(!(is.numeric(statsplot1()[[input$socialfilter]])))
selectInput("socialfiltergroup","Choose Group Variable for Statisitical Plot:", choices=colnames(recreation_visit)[names(recreation_visit) %in% c("Visitcount", "Participant Id", input$socialfilter) == FALSE])
})
vards2 <- reactive ({
req(input$socialfiltergroup)
recreation_visit %>%
select(.data[[input$socialfiltergroup]]) %>%
unique()
})
output$filter2 <- renderUI({
radioButtons("fil2","Filter", choices=vards2())
})
}
# Run the application
shinyApp(ui = ui, server = server)
dput(head(recreation_visit))
structure(list(`Participant Id` = c("23", "15", "930", "619",
"359", "699"), `Pub Id` = c("894", "1798", "892", "1798", "893",
"1798"), Dates = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Mar 2022",
"Apr 2022", "May 2022", "Jun 2022", "Jul 2022", "Aug 2022", "Sep 2022",
"Oct 2022", "Nov 2022", "Dec 2022", "Jan 2023", "Feb 2023", "Mar 2023",
"Apr 2023", "May 2023"), class = "factor"), `Time Period` = structure(c(7L,
8L, 8L, 8L, 8L, 8L), .Label = c("0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23"), class = "factor"),
Weekday = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Mon",
"Tue", "Wed", "Thu", "Fri", "Sat", "Sun"), class = "factor"),
`Workday Type` = c("Working Day", "Working Day", "Working Day",
"Working Day", "Working Day", "Working Day"), Session = structure(c(1L,
1L, 1L, 1L, 1L, 1L), .Label = c("Morning", "Afternoon", "Evening",
"Midnight"), class = "factor"), `Pub Region` = c("Central",
"North-west", "Central", "North-west", "Central", "North-west"
)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))