When I use querychat, charts that display factors begin to order levels alphabetically. This makes me think that querychat drops factor levels when processing the data. Here is a toy example.
A shiny app
library(shiny)
library(bslib)
library(forcats)
library(ggplot2)
library(dplyr)
relig_choices <- c("All", levels(gss_cat$relig))
ui <- page_sidebar(
title = "GSS Marital Status",
sidebar = sidebar(
selectInput("relig", "Religion", choices = relig_choices, selected = "All")
),
plotOutput("marital_plot")
)
server <- function(input, output, session) {
filtered_data <- reactive({
if (input$relig == "All") {
gss_cat
} else {
filter(gss_cat, relig == input$relig)
}
})
output$marital_plot <- renderPlot({
ggplot(filtered_data(), aes(x = marital, fill = marital)) +
geom_bar() +
theme(
axis.text = element_text(size = 16),
axis.title = element_text(size = 18)
)
})
}
shinyApp(ui, server)
The querychat version
library(shiny)
library(bslib)
library(forcats)
library(ggplot2)
library(dplyr)
library(querychat)
qc <- QueryChat$new(gss_cat, greeting = "Hello")
ui <- page_sidebar(
title = "GSS Marital Status",
sidebar = qc$sidebar(),
plotOutput("marital_plot")
)
server <- function(input, output, session) {
qc_vals <- qc$server()
filtered_data <- reactive({
qc_vals$df()
})
output$marital_plot <- renderPlot({
ggplot(filtered_data(), aes(x = marital)) +
geom_bar()
})
}
shinyApp(ui, server)
When I use querychat, charts that display factors begin to order levels alphabetically. This makes me think that querychat drops factor levels when processing the data. Here is a toy example.
A shiny app
The querychat version