diff --git a/Dockerfile b/Dockerfile index 592dad8..62a0a80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,15 @@ FROM rocker/geospatial:latest WORKDIR /code RUN install2.r --error \ + bsicons \ bslib \ + duckdbfs \ + fontawesome \ + gt \ + markdown \ shiny \ shinychat \ - tidyverse \ - duckdbfs \ - markdown + tidyverse RUN installGithub.r cboettig/mapgl tidyverse/ellmer diff --git a/app.R b/app.R index 3b2df57..36215b6 100644 --- a/app.R +++ b/app.R @@ -5,6 +5,10 @@ library(shinychat) library(mapgl) library(tidyverse) library(duckdbfs) +library(fontawesome) +library(bsicons) +library(gt) +duckdbfs::load_spatial() pmtiles <- "https://data.source.coop/cboettig/us-boundaries/mappinginequality.pmtiles" @@ -13,21 +17,30 @@ ui <- page_sidebar( sidebar = sidebar( - textAreaInput("chat", - "Ask me a question!", - value = "Which state has the highest average social vulnerability?", + textAreaInput("chat", + span(bs_icon("robot", size = "1.5em"), "Ask me a question!"), + value = "Which county has the highest average social vulnerability?", width = "100%", height = 100 ), - verbatimTextOutput("sql_code"), - textOutput("explanation"), + actionButton("user_msg", "Go!", icon = icon("paper-plane"), width = "50%"), + + accordion( + open = FALSE, + accordion_panel("generated SQL Code", + verbatimTextOutput("sql_code"), + ), + accordion_panel("Explanation", + textOutput("explanation"), + ) + ), input_switch("redlines", "Redlined Areas"), input_switch("svi", "Social Vulnerability", value = TRUE), input_switch("richness", "Biodiversity Richness"), input_switch("rsr", "Biodiversity Range Size Rarity"), - width = 300, + width = 350, ), titlePanel("Demo App"), @@ -41,8 +54,9 @@ ui <- page_sidebar( col_widths = c(8,4) ), - tableOutput("table") + gt_output("table"), +theme = bs_theme(version = "5") ) svi <- "https://data.source.coop/cboettig/social-vulnerability/svi2020_us_tract.parquet" |> @@ -56,7 +70,10 @@ system_prompt = glue::glue(' You are a helpful agent who always replies strictly in JSON-formatted text. Your task is to translate the users question into a SQL query that will be run against the "svi" table in a duckdb database. The duckdb database has a -spatial extension which understands PostGIS operations as well. +spatial extension which understands PostGIS operations as well. + + +Be careful to limit any return to no more than 50 rows. The table schema is @@ -80,17 +97,19 @@ server <- function(input, output, session) { system_prompt = system_prompt ) - observeEvent(input$chat, { + observeEvent(input$user_msg, { stream <- chat$chat(input$chat) chat_append("chat", stream) response <- jsonlite::fromJSON(stream) - output$sql_code <- renderText({response$query}) + output$sql_code <- renderText({stringr::str_wrap(response$query, width=40)}) output$explanation <- renderText({response$explanation}) df <- DBI::dbGetQuery(con, response$query) - output$table <- renderTable(df, striped = TRUE) + + df <- df |> select(-any_of("Shape")) + output$table <- render_gt(df, height=300) })