Description
This is related to a dialog to "Import from ClimMob" for our new set of Tricot Analyses menu:
1, "Server Name" runs the parameter server
. This has a drop down list of the four server names that this variable takes: climmob3
, 1000FARMS
, AVISA
, RTB
. server = "climmob3"
is the default
2. API Key runs the parameter key
. This can have a button next to it where you browse .txt files for the stored key in a .txt file. This is similar to how we get the key in the Import from OpenAppBuilder
and Import from RapidPro
dialogs
key <- read.table("path/to/key.txt", quote="\"", comment.char="")
- The "Find forms" button runs the R code
getProjectsCM(server = <server name>, key = <key>)
. This R code gives a table, and we just want to return in the drop down list theproject_id
column in this list. I assume this is similar to how the "Import from ODK" dialog works. - There is a checkbox, default unchecked:
a) When you click OK, the following runs:
user_owner <- project_list %>% dplyr::filter(project_id == project) %>% dplyr::pull(user_owner)
ClimMobTools::getDataCM(key = <key>
project = < project ID selected in the drop down >,
userowner = user_owner,
server = <server>,
pivot.wider = TRUE)
b) We get one data frame, which is called the name given in the ucrSave after "New Data Frame Name:"
R Code Example:
# get a list of projects
key <- "d39a3c66-5822-4930-a9d4-50e7da041e77"
# or in our case we will store the key in a .txt file (without the quotes) and call by:
# key <- read.table("C:/Users/lclem/Downloads/tricot_api_key.txt", quote="\"", comment.char="")
project_list <- ClimMobTools::getProjectsCM(key = key, server = "climmob3")
# display the project_list$project_id in the list
Second bit that runs gets the data from ClimMob
# Let's say they choose the project titled "breadwheat":
# and that the name in the ucrSave is "breadwheat"
project <- "breadwheat"
user_owner <- project_list %>% dplyr::filter(project_id == project) %>% dplyr::pull(user_owner)
breadwheat <- ClimMobTools::getDataCM(key = key,
project = project,
userowner = user_owner, # we run this ourselves
server = "climmob3",
pivot.wider = TRUE)
data_book$import_data(data_tables=list(breadwheat = breadwheat))
Third bit that runs is only run if the checkbox is checked. I'll outline this in the next message