【发布时间】:2020-08-07 12:47:25
【问题描述】:
我在 Microsoft PowerBi 中使用 R 脚本作为数据源时遇到问题。我认为这是 PowerBi 的根本问题,但短期内我需要在 R 中找到解决方案。
基本上,如果我使用 R Studio,PowerBi 似乎无法处理将发送到控制台的消息。
在 R 脚本中,我使用 REST API 从 URL 请求数据。接收到的 JSON 消息被转换为 R 数据帧。在 PowerBi 中使用脚本作为数据源时,这仅在我将详细设置设置为 FALSE 时才有效,即如果我使用 R Studio,则不会向控制台发送任何消息(特别是输入的数据)。
response <- GET(<url>,
body = list(),
add_headers(.headers = c('<identity token>' = ID_to_use)),
verbose(data_out = FALSE,
data_in = FALSE,
info = FALSE,
ssl = FALSE),
encode = "json")
但是,我没有关闭传入/传出 JSON 标头消息的选项(这将回来咬人!)。
<< {"identity":" <token>"}
* Connection #54 to <host> left intact
No encoding supplied: defaulting to UTF-8.
-> GET <URL request> HTTP/1.1
-> Host: <host>
-> User-Agent: libcurl/7.64.1 r-curl/4.3 httr/1.4.1
-> Accept-Encoding: deflate, gzip
-> Accept: application/json, text/xml, application/xml, */*
-> <Identity>: <Identity>
->
<- HTTP/1.1 200 OK
<- X-Session-Expiry: 3599
<- Content-Type: application/json
<- Transfer-Encoding: chunked
<- Date: Thu, 06 Aug 2020 16:14:26 GMT
<- Server: <Server>
<-
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
来自 R 帮助
.
.
verbose() uses the following prefixes to distinguish between different components of the http messages:
* informative curl messages
-> headers sent (out)
>> data sent (out)
*> ssl data sent (out)
<- headers received (in)
<< data received (in)
<* ssl data received (in)
.
.
将详细设置切换为 FALSE 适用于单个请求,但是,我需要将请求置于循环中并继续请求更多数据,直到 API 网关指示不再接收数据。在脚本中发送/接收五个或更多请求/回复时,PowerBi 似乎失败。
仅从观察来看,我认为这与 JSON Header 消息堆积有关。
我尝试了多种方法,但似乎没有任何效果:sink('NUL')、invisible()、capture.output()。
任何帮助将不胜感激。
【问题讨论】: