Spaces:
Runtime error
Runtime error
button
Browse files- Dockerfile +6 -3
- app.R +30 -11
Dockerfile
CHANGED
@@ -3,12 +3,15 @@ FROM rocker/geospatial:latest
|
|
3 |
WORKDIR /code
|
4 |
|
5 |
RUN install2.r --error \
|
|
|
6 |
bslib \
|
|
|
|
|
|
|
|
|
7 |
shiny \
|
8 |
shinychat \
|
9 |
-
tidyverse
|
10 |
-
duckdbfs \
|
11 |
-
markdown
|
12 |
|
13 |
RUN installGithub.r cboettig/mapgl tidyverse/ellmer
|
14 |
|
|
|
3 |
WORKDIR /code
|
4 |
|
5 |
RUN install2.r --error \
|
6 |
+
bsicons \
|
7 |
bslib \
|
8 |
+
duckdbfs \
|
9 |
+
fontawesome \
|
10 |
+
gt \
|
11 |
+
markdown \
|
12 |
shiny \
|
13 |
shinychat \
|
14 |
+
tidyverse
|
|
|
|
|
15 |
|
16 |
RUN installGithub.r cboettig/mapgl tidyverse/ellmer
|
17 |
|
app.R
CHANGED
@@ -5,6 +5,10 @@ library(shinychat)
|
|
5 |
library(mapgl)
|
6 |
library(tidyverse)
|
7 |
library(duckdbfs)
|
|
|
|
|
|
|
|
|
8 |
|
9 |
pmtiles <- "https://data.source.coop/cboettig/us-boundaries/mappinginequality.pmtiles"
|
10 |
|
@@ -13,21 +17,30 @@ ui <- page_sidebar(
|
|
13 |
|
14 |
sidebar = sidebar(
|
15 |
|
16 |
-
textAreaInput("chat",
|
17 |
-
"Ask me a question!",
|
18 |
-
value = "Which
|
19 |
width = "100%",
|
20 |
height = 100
|
21 |
),
|
22 |
|
23 |
-
|
24 |
-
textOutput("explanation"),
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
input_switch("redlines", "Redlined Areas"),
|
27 |
input_switch("svi", "Social Vulnerability", value = TRUE),
|
28 |
input_switch("richness", "Biodiversity Richness"),
|
29 |
input_switch("rsr", "Biodiversity Range Size Rarity"),
|
30 |
-
width =
|
31 |
),
|
32 |
titlePanel("Demo App"),
|
33 |
|
@@ -41,8 +54,9 @@ ui <- page_sidebar(
|
|
41 |
col_widths = c(8,4)
|
42 |
),
|
43 |
|
44 |
-
|
45 |
|
|
|
46 |
)
|
47 |
|
48 |
svi <- "https://data.source.coop/cboettig/social-vulnerability/svi2020_us_tract.parquet" |>
|
@@ -56,7 +70,10 @@ system_prompt = glue::glue('
|
|
56 |
You are a helpful agent who always replies strictly in JSON-formatted text.
|
57 |
Your task is to translate the users question into a SQL query that will be run
|
58 |
against the "svi" table in a duckdb database. The duckdb database has a
|
59 |
-
spatial extension which understands PostGIS operations as well.
|
|
|
|
|
|
|
60 |
|
61 |
The table schema is <schema>
|
62 |
|
@@ -80,17 +97,19 @@ server <- function(input, output, session) {
|
|
80 |
system_prompt = system_prompt
|
81 |
)
|
82 |
|
83 |
-
observeEvent(input$
|
84 |
stream <- chat$chat(input$chat)
|
85 |
|
86 |
chat_append("chat", stream)
|
87 |
response <- jsonlite::fromJSON(stream)
|
88 |
|
89 |
-
output$sql_code <- renderText({response$query})
|
90 |
output$explanation <- renderText({response$explanation})
|
91 |
|
92 |
df <- DBI::dbGetQuery(con, response$query)
|
93 |
-
|
|
|
|
|
94 |
|
95 |
})
|
96 |
|
|
|
5 |
library(mapgl)
|
6 |
library(tidyverse)
|
7 |
library(duckdbfs)
|
8 |
+
library(fontawesome)
|
9 |
+
library(bsicons)
|
10 |
+
library(gt)
|
11 |
+
duckdbfs::load_spatial()
|
12 |
|
13 |
pmtiles <- "https://data.source.coop/cboettig/us-boundaries/mappinginequality.pmtiles"
|
14 |
|
|
|
17 |
|
18 |
sidebar = sidebar(
|
19 |
|
20 |
+
textAreaInput("chat",
|
21 |
+
span(bs_icon("robot", size = "1.5em"), "Ask me a question!"),
|
22 |
+
value = "Which county has the highest average social vulnerability?",
|
23 |
width = "100%",
|
24 |
height = 100
|
25 |
),
|
26 |
|
27 |
+
actionButton("user_msg", "Go!", icon = icon("paper-plane"), width = "50%"),
|
|
|
28 |
|
29 |
+
|
30 |
+
accordion(
|
31 |
+
open = FALSE,
|
32 |
+
accordion_panel("generated SQL Code",
|
33 |
+
verbatimTextOutput("sql_code"),
|
34 |
+
),
|
35 |
+
accordion_panel("Explanation",
|
36 |
+
textOutput("explanation"),
|
37 |
+
)
|
38 |
+
),
|
39 |
input_switch("redlines", "Redlined Areas"),
|
40 |
input_switch("svi", "Social Vulnerability", value = TRUE),
|
41 |
input_switch("richness", "Biodiversity Richness"),
|
42 |
input_switch("rsr", "Biodiversity Range Size Rarity"),
|
43 |
+
width = 350,
|
44 |
),
|
45 |
titlePanel("Demo App"),
|
46 |
|
|
|
54 |
col_widths = c(8,4)
|
55 |
),
|
56 |
|
57 |
+
gt_output("table"),
|
58 |
|
59 |
+
theme = bs_theme(version = "5")
|
60 |
)
|
61 |
|
62 |
svi <- "https://data.source.coop/cboettig/social-vulnerability/svi2020_us_tract.parquet" |>
|
|
|
70 |
You are a helpful agent who always replies strictly in JSON-formatted text.
|
71 |
Your task is to translate the users question into a SQL query that will be run
|
72 |
against the "svi" table in a duckdb database. The duckdb database has a
|
73 |
+
spatial extension which understands PostGIS operations as well.
|
74 |
+
|
75 |
+
|
76 |
+
Be careful to limit any return to no more than 50 rows.
|
77 |
|
78 |
The table schema is <schema>
|
79 |
|
|
|
97 |
system_prompt = system_prompt
|
98 |
)
|
99 |
|
100 |
+
observeEvent(input$user_msg, {
|
101 |
stream <- chat$chat(input$chat)
|
102 |
|
103 |
chat_append("chat", stream)
|
104 |
response <- jsonlite::fromJSON(stream)
|
105 |
|
106 |
+
output$sql_code <- renderText({stringr::str_wrap(response$query, width=40)})
|
107 |
output$explanation <- renderText({response$explanation})
|
108 |
|
109 |
df <- DBI::dbGetQuery(con, response$query)
|
110 |
+
|
111 |
+
df <- df |> select(-any_of("Shape"))
|
112 |
+
output$table <- render_gt(df, height=300)
|
113 |
|
114 |
})
|
115 |
|