country_codes <- list(code = c("US", "DE"))
x <- ghql_con$exec(
qry$queries$country_data,
country_codes
) # We created a query named "country_data"
jsonlite::fromJSON(x)
#> $data
#> $data$countries
#> code name capital phone languages
#> 1 DE Germany Berlin 49 de, German
#> 2 US United States Washington D.C. 1 en, English
ws://
or wss://
(vs http://
/ https://
)ws_counter <- 1
ws2 <- websocket::WebSocket$new(
"ws://echo.websocket.events/", autoConnect = FALSE
)
ws2$onMessage(\(event) {
ws_counter <<- ws_counter + 1 # Add 1 to global ws_counter var
cat(ws_counter, "\n")
})
ws_counter
#> 1
ws2$connect()
#> 2
ws2$send("update")
#> 3
ws2$send("update again")
#> 4
ws2$close()
From RProtoBuf paper
resp <- httr2::request("https://demo.ocpu.io/MASS/data/Animals/pb") |>
httr2::req_perform()
output <- httr2::resp_body_raw(resp) |>
protolite::unserialize_pb() # This is the important part
identical(output, MASS::Animals)
#> [1] TRUE
head(output)
#> body brain
#> Mountain beaver 1.35 8.1
#> Cow 465.00 423.0
#> Grey wolf 36.33 119.5
#> Goat 27.66 115.0
#> Guinea pig 1.04 5.5
#> Dipliodocus 11700.00 50.0
pkg <- "tibble"
func <- "tibble"
args <- list(id = 1:3, letter = sample(letters, 3))
payload <- protolite::serialize_pb(args) # To protobuff
resp <- httr2::request("https://cloud.opencpu.org/ocpu/library") |>
httr2::req_url_path_append(pkg, "R", func, "pb") |>
httr2::req_body_raw(payload, type = "application/protobuf") |>
httr2::req_perform()
httr2::resp_body_raw(resp) |>
protolite::unserialize_pb() # Back to R
#> # A tibble: 3 × 2
#> id letter
#> * <int> <chr>
#> 1 1 n
#> 2 2 f
#> 3 3 k
DSLC.io/wapir | Jon Harmon | wapir.io