Spaces:
Running
Running
Update app.R to use RSQLite instead of duckdb
Browse files
app.R
CHANGED
|
@@ -1,58 +1,58 @@
|
|
| 1 |
-
# ISA 401 OEWS Jobs Explorer
|
| 2 |
-
# A Shiny app for exploring U.S. Occupational Employment and Wage Statistics
|
| 3 |
-
|
| 4 |
-
library(shiny)
|
| 5 |
-
library(bslib)
|
| 6 |
-
library(querychat)
|
| 7 |
-
library(DT)
|
| 8 |
-
library(dplyr)
|
| 9 |
-
library(
|
| 10 |
-
|
| 11 |
-
# Load preprocessed data
|
| 12 |
-
oews <- readRDS("data/oews.rds")
|
| 13 |
-
|
| 14 |
-
# Step 1: Create QueryChat object
|
| 15 |
-
client = ellmer::chat_openai(
|
| 16 |
-
model = "gpt-5-mini-2025-08-07",
|
| 17 |
-
credentials = function(){return(Sys.getenv("OPENAI_API_KEY"))}
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
qc = querychat::querychat(
|
| 21 |
-
oews,
|
| 22 |
-
client = client,
|
| 23 |
-
greeting = "Welcome to Our ISA 401 Assistant for Understanding the OEWS Dataset",
|
| 24 |
-
extra_instructions = "data/extra_instructions.md",
|
| 25 |
-
data_description = 'data/data_desc.md'
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
## Based on the documentation:
|
| 29 |
-
# https://posit-dev.github.io/querychat/r/articles/build.html#programmatic-filtering
|
| 30 |
-
|
| 31 |
-
# Step 2: Add UI component
|
| 32 |
-
ui <- bslib::page_sidebar(
|
| 33 |
-
sidebar = qc$sidebar(),
|
| 34 |
-
bslib::card(
|
| 35 |
-
bslib::card_header("Data Table"),
|
| 36 |
-
DT::DTOutput("table")
|
| 37 |
-
),
|
| 38 |
-
bslib::card(
|
| 39 |
-
fill = FALSE,
|
| 40 |
-
bslib::card_header("SQL Query"),
|
| 41 |
-
shiny::verbatimTextOutput("sql")
|
| 42 |
-
)
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
# Step 3: Use reactive values in server
|
| 46 |
-
server <- function(input, output, session) {
|
| 47 |
-
qc_vals <- qc$server()
|
| 48 |
-
|
| 49 |
-
output$table <- DT::renderDT({
|
| 50 |
-
DT::datatable(qc_vals$df(), fillContainer = TRUE)
|
| 51 |
-
})
|
| 52 |
-
|
| 53 |
-
output$sql <- shiny::renderText({
|
| 54 |
-
qc_vals$sql() %||% "SELECT * FROM oews"
|
| 55 |
-
})
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
shiny::shinyApp(ui, server)
|
|
|
|
| 1 |
+
# ISA 401 OEWS Jobs Explorer
|
| 2 |
+
# A Shiny app for exploring U.S. Occupational Employment and Wage Statistics
|
| 3 |
+
|
| 4 |
+
library(shiny)
|
| 5 |
+
library(bslib)
|
| 6 |
+
library(querychat)
|
| 7 |
+
library(DT)
|
| 8 |
+
library(dplyr)
|
| 9 |
+
library(RSQLite)
|
| 10 |
+
|
| 11 |
+
# Load preprocessed data
|
| 12 |
+
oews <- readRDS("data/oews.rds")
|
| 13 |
+
|
| 14 |
+
# Step 1: Create QueryChat object
|
| 15 |
+
client = ellmer::chat_openai(
|
| 16 |
+
model = "gpt-5-mini-2025-08-07",
|
| 17 |
+
credentials = function(){return(Sys.getenv("OPENAI_API_KEY"))}
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
qc = querychat::querychat(
|
| 21 |
+
oews,
|
| 22 |
+
client = client,
|
| 23 |
+
greeting = "Welcome to Our ISA 401 Assistant for Understanding the OEWS Dataset",
|
| 24 |
+
extra_instructions = "data/extra_instructions.md",
|
| 25 |
+
data_description = 'data/data_desc.md'
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
## Based on the documentation:
|
| 29 |
+
# https://posit-dev.github.io/querychat/r/articles/build.html#programmatic-filtering
|
| 30 |
+
|
| 31 |
+
# Step 2: Add UI component
|
| 32 |
+
ui <- bslib::page_sidebar(
|
| 33 |
+
sidebar = qc$sidebar(),
|
| 34 |
+
bslib::card(
|
| 35 |
+
bslib::card_header("Data Table"),
|
| 36 |
+
DT::DTOutput("table")
|
| 37 |
+
),
|
| 38 |
+
bslib::card(
|
| 39 |
+
fill = FALSE,
|
| 40 |
+
bslib::card_header("SQL Query"),
|
| 41 |
+
shiny::verbatimTextOutput("sql")
|
| 42 |
+
)
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
# Step 3: Use reactive values in server
|
| 46 |
+
server <- function(input, output, session) {
|
| 47 |
+
qc_vals <- qc$server()
|
| 48 |
+
|
| 49 |
+
output$table <- DT::renderDT({
|
| 50 |
+
DT::datatable(qc_vals$df(), fillContainer = TRUE)
|
| 51 |
+
})
|
| 52 |
+
|
| 53 |
+
output$sql <- shiny::renderText({
|
| 54 |
+
qc_vals$sql() %||% "SELECT * FROM oews"
|
| 55 |
+
})
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
shiny::shinyApp(ui, server)
|