Regression Trends SMART R-Plugin


  1. SMART 7.4 or above
  2. the R plugin for SMART
  3. R (Download R-4.2.2 for Windows. The R-project for statistical computing.)
  4. R Studios (Download the RStudio IDE - RStudio)
  5. R Tools (RTools: Toolchains for building R and R packages from source on Windows)

An example on how to use the R plugin with pre-written code to analyze illegal activity data in protected areas via the Spatial Monitoring and Reporting Tool (SMART).

In this example, we use a code snippet along with SMART queries of illegal activity observations (traps, illegal hunting camps, and offenders), and divide them by effort (daily km of patrols) to obtain a density estimate for each. Then we plot them with a linear and LOESS regression to examine the general and fluctuating trends in the data.

I have created a GitHub page where I will deposit various code snippets and hopefully get a team of R users to help populate it with more. If you would like to join me, let me know! Also, if you have any specific analyses you would like to automate with the R plugin that doesn’t already exist in SMART, describe it to me and I will see what I can do.

Get the code here: GitHub - RJGrayEcology/smartR: A code snippet repository for reproducible analyses in the Spatial Monitoring and Reporting Tool (SMART) conservation software

Watch a video tutorial here: Regression Trends SMART R-Plugin - YouTube


Thanks for sharing! If any SMART user is interested in using R, we have some updated documentation to share to assist you. Thanks

Yes please do! Has baffled me how to implement. The vid for this analysis helps (esp the last few seconds where Russell actually runs the script inside smart! seeing what it should look like etc) but still would value explainers/worked examples of how to start from scratch with getting an R script to run inside smart. Thanks J

1 Like

Very neat and glad to see example vid of running R inside Smart. I just couldn’t figure out the most basic step how to get the script to read an actual query. The thing it seems I didn’t know about was commandArgs. Is that a base R function?
Tiny q, but should line 23 in the code on github be “myquery3 = args[3]” (this is how it appears in your vid)

1 Like

The only guidance I could find to get going with r-plugin was this:
and this doesn’t provide any example script or give any clue what commands required in the script to enable it to actually read the queries.

Hi Jeremy,

I have just updated the Resource Library with the updated guidance. Here is the link -

Thanks again to @Russell-SVW for all his help reviewing and helping us improve this guidance!


I only see the image above, the actual document is here i think:

1 Like

I think we could also add (at the end) as a resource the R-Graph Gallery website ( which is a compilation of all types of graphs and maps that can be made using R with example R code to use and modify.

I think accessing SMART data directly from R and working with the data in R should be a future development. I would be happy to participate in the development of a package to accomplish this task assuming we can get the pieces needed from other packages/projects. smaRt

If someone shows me the structure of the API, I can probably create an R package that wraps the API and allows users to make queries on their Connect data from R. I tried on my own Connect instance and the API seems to be really messy for some reason. I can access the queries, but the outputs come up as a bunch of html noise.

Will look into it more later when I have time.

If you want to play around with it a bit, this is as far as I’ve gotten before things turn ugly:

open libraries


add your SMART Connect sign in page URL here

url ← “your/smartconnect/url”

run this to log in to your SMART Connect server

session ← session(url)

form ← html_form(session)[[1]]
fl_fm ← html_form_set(form,
j_username = “username”,
j_password = “password”)
main_page ← session_submit(session, fl_fm)

in SMART Connect, when you run a query, copy and paste the link

query_url <-session_jump_to(main_page,”)

1 Like

This is great. You are trying to get the output of a query right? I think it would be great to access the data themselves and be able to create summaries from raw.

I added library(jsonlite) and replaced the last chunk


#add your SMART Connect sign in page URL here
url<- “https://your_connect_url:8443/server”

#run this to log in to your SMART Connect server
session ← session(url)

form ← html_form(session)[[1]]
fl_fm ← html_form_set(form,
j_username = “your username”,
j_password = “your password”)
main_page ← session_submit(session, fl_fm)

#in SMART Connect, when you run a query, copy and paste the link

query_url <-session_jump_to(main_page, “your_link_in_connect_to_a_file”) # ends in /file

data<- httr::content(query_url$response, as = “text”) %>% parse_json()

I did this quickly. the structure of the data output makes sense but I have not checked its content (but I got lat lon values at least)! This is how it looks:

[1] 11.5724

[1] -0.7248667

[1] “Point”

[1] 0

[1] “Monitoreo Karukinka”

[1] “1.0.433”

[1] “2022-11-11T12:01:22.888+01:00”

[1] “12210a5fe0a745a18f09a60ddd5a5279”

[1] “ae25a3a3ff934fa38ea70356588d57ed”

[1] -0.7248667

[1] 11.5724

[1] “ae25a3a3ff934fa38ea70356588d57ed”

[1] “6334d315768f4d04a4e482c50239d009”

[1] “c84e5ef2da2a40a09587c5ae7376999c”

[1] “patrol”

[1] “{}”

[1] “{}”

[1] “e:b99744b6eb214da182095afb66f73c06”

[1] “pm:35e1311ae48742a4acfbcde8fe246fd9”

[1] TRUE

[1] 1

[1] “NewPatrol”

[1] “03e41caf13654f449d587d123fc6323e”

[1] “2022/11/11”

[1] “12:01:22”

[1] “tt:58158398a8ff4c7dbc867f9e723c8a4c”

[1] “pt:2213a07880da4e3ca30b121bbd1b1a8c”

[1] TRUE

[1] “Feature”

[1] “FeatureCollection”

I know patrols have at least 5 files so how to get the corresponding files into a consistent patrol data … I don’t know yet.
How to get the actual /files links wished by the user? I dunno yet.


Would you be interested in exploring how we wrap SMART APIs and feed them into a hosted r-shiny instance?

Hey Jonathan, actually that would be quote easy even via the R plugin, I could create a nice flex dashboard with numerous pages of interactive plots. Maybe I’ll throw one together over the weekend and add it to the smartR github project.

I’ll test out Diego’s code fix now and see if I can get one to wrap a connect instance and autoupdate with new information. That would be a nice, free alternative to a hosted dashboard page.

Tried out this solution, but at line:
“# get vector data
data ← content(query_url$response, as = “text”)%>%parse_json()”

I got the error:
"Error: parse error: trailing garbage
“Conservation Area Name”,“Waypoint Date”,“X”,“Y”,“Actio
(right here) ------^”

I tried manually parsing, and trying about 10 other solutions from stackoverflow. If the query output from the SMART Connect API was structured into a table instead of a raw JSON string this would be so much easier to streamline…

Instead its just this mess