@@ -26,6 +26,7 @@ library(diades.atlas)
26
26
library(dplyr)
27
27
library(leaflet)
28
28
library(ggplot2)
29
+ library(sf)
29
30
```
30
31
31
32
## Data exploration
@@ -34,23 +35,12 @@ library(ggplot2)
34
35
35
36
Do not forget to set environment variables in .Renviron
36
37
``` {r}
37
- postgis_host <- Sys.getenv("POSTGRES_HOST")
38
- postgis_user <- Sys.getenv("POSTGRES_USER")
39
- postgis_password <- Sys.getenv("POSTGRES_PASSWORD")
40
-
41
- con <- DBI::dbConnect(
42
- RPostgres::Postgres(),
43
- host = Sys.getenv("POSTGRES_HOST", diades.atlas:::get_golem_config("POSTGRES_HOST")),
44
- dbname = Sys.getenv("POSTGRES_DBNAME", diades.atlas:::get_golem_config("POSTGRES_DBNAME")),
45
- port = Sys.getenv("POSTGRES_PORT", diades.atlas:::get_golem_config("POSTGRES_PORT")),
46
- user = Sys.getenv("POSTGRES_USER", "diadesatlas_r"),
47
- password = Sys.getenv("POSTGRES_PASS", "diadesPassword"),
48
- options = "-c search_path=diadesatlas"
49
- )
50
- # Listtables
51
- # DBI::dbListTables(con)
52
- # DBI::dbListObjects(con)
38
+ session <- shiny::MockShinySession$new() #new.env()
39
+ connect(session)
40
+ con <- get_con(session)
41
+ ```
53
42
43
+ ``` {r, eval=FALSE}
54
44
# Get the names of all the tables in the schema
55
45
all_schemas <- DBI::dbGetQuery(con, "SELECT table_name FROM information_schema.tables WHERE table_schema='diadesatlas'")
56
46
all_schemas
@@ -64,21 +54,13 @@ casestudy <- tbl(con, dbplyr::in_schema("diadesatlas", "casestudy"))
64
54
casestudy
65
55
```
66
56
67
- ### Create connection
68
-
69
- ``` {r, eval=FALSE}
70
- my_dm <- dm_from_src(con, schema = "diadesatlas", learn_keys = TRUE)
71
- my_dm
72
- ```
73
-
74
57
### Function to collect data
75
58
``` {r, eval=FALSE}
76
59
# empty
77
60
# dplyr::tbl(con, dbplyr::in_schema("diadesatlas", "cices51")) %>% collect()
78
61
# services ?
79
62
# dplyr::tbl(con, dbplyr::in_schema("diadesatlas", "cices")) %>% collect()
80
- # services new
81
- dplyr::tbl(con, dbplyr::in_schema("diadesatlas", "es_diades")) %>% collect()
63
+
82
64
# geometry of all basin
83
65
dplyr::tbl(con, dbplyr::in_schema("diadesatlas", "basin_location")) %>% collect()
84
66
# Model results over the years
@@ -105,24 +87,41 @@ dplyr::tbl(con, dbplyr::in_schema("diadesatlas", "species")) %>% collect()
105
87
### Prepare json files
106
88
Create all json data used on the home page of the app
107
89
``` {r, eval=FALSE}
108
- # List of case studies
109
- casestudy <- dplyr::tbl(con, dbplyr::in_schema("diadesatlas", "casestudy")) %>% collect()
110
- # List of the corresponding basins
111
- casestudy_basin <- dplyr::tbl(con, dbplyr::in_schema("diadesatlas", "casestudy_basin")) %>% collect()
112
- # Put them two together
113
- cstd <- full_join(casestudy, casestudy_basin) %>% filter(publishable)
90
+ # # List of case studies
91
+ # casestudy <- dplyr::tbl(con, dbplyr::in_schema("diadesatlas", "casestudy")) %>% collect()
92
+ # # List of the corresponding basins
93
+ # casestudy_basin <- dplyr::tbl(con, dbplyr::in_schema("diadesatlas", "casestudy_basin")) %>% collect()
94
+ # # Put them two together
95
+ # cstd <- full_join(casestudy, casestudy_basin) %>% filter(publishable) %>% collect( )
114
96
115
- # Get the features for drawing the polygons on the map
116
- qry <- "SELECT ST_Transform(diadesatlas.basin_outlet.simplified_geom, 4326) as geom, basin_id as basin_id FROM diadesatlas.basin_outlet"
117
97
118
- # i then read as an sf object
119
- pols <- sf::st_read(con, query = qry, geom = "geom") %>%
120
- filter(basin_id %in% casestudy_basin$basin_id) %>%
121
- left_join(cstd)
122
- pols %>%
98
+ casestudy_new <- sf::st_read(con,
99
+ query = "SELECT casestudy_id, casestudy_name, geom FROM diadesatlas.casestudy", geom = "geom") %>%
100
+ # fake basin_id to be compatabible with mod_b_second.R
101
+ mutate(basin_id = 1:n()) %>%
102
+ st_transform(crs = 4326)
103
+
104
+ casestudy_new %>%
123
105
geojson::as.geojson() %>%
124
106
geojson::geo_write(here::here("inst/casestudy.json"))
125
107
108
+
109
+ # Get the features for drawing the polygons on the map
110
+ # qry <- "SELECT ST_Transform(diadesatlas.basin_outlet.simplified_geom, 4326) as geom, basin_id as basin_id FROM diadesatlas.basin_outlet"
111
+
112
+ # qry <- "SELECT diadesatlas.basin_outlet.simplified_geom as geom, basin_id as basin_id FROM diadesatlas.basin_outlet"
113
+ #
114
+ # pols <- sf::st_read(con, query = qry, geom = "geom") %>%
115
+ # st_transform(crs = 4326)
116
+ #
117
+ # # i then read as an sf object
118
+ # pols %>%
119
+ # filter(basin_id %in% casestudy_basin$basin_id) %>%
120
+ # left_join(cstd)
121
+ # pols %>%
122
+ # geojson::as.geojson() %>%
123
+ # geojson::geo_write(here::here("inst/casestudy.json"))
124
+
126
125
# List of ecosystem services
127
126
ecosystems <- dplyr::tbl(con, dbplyr::in_schema("diadesatlas", "ecosystem_service")) %>% collect()
128
127
ecosystems %>%
@@ -153,6 +152,27 @@ species %>%
153
152
jsonlite::write_json(here::here("inst/species.json"))
154
153
```
155
154
155
+ ### Explore ecosystem services table
156
+ ``` {r}
157
+ r <- list(lg = 'en')
158
+ datasets <- generate_datasets(con = con)
159
+ .globals <- getFromNamespace('.globals', 'shiny')
160
+
161
+ # simulate a species_list
162
+ session$options$golem_options$species_list <- datasets$species_list
163
+ .globals$domain <- session
164
+
165
+ golem::get_golem_options("species_list")
166
+
167
+ # debugonce(ecosystem_table)
168
+ ecosystem_table(species = "Alosa alosa",
169
+ case_study = 5,
170
+ ecosystem = '1_4',
171
+ r = r,
172
+ session = session) %>%
173
+ DT::datatable()
174
+ ```
175
+
156
176
157
177
### Stop connection
158
178
0 commit comments