小编Mar*_*keD的帖子

使用...修改功能中的嵌套列表

在R中,我试图创建一种方法来将函数参数转换...为闭包函数中预定列表中的值.

我希望能够做到这样的事情:

function_generator <- function(args_list = list(a = "a", 
                                                b = "b", 
                                                c = list(d = "d", 
                                                         e = "e")){

    g <- function(...){
         ## ... will have same names as args list
         ## e.g. a = "changed_a", d = "changed_d"
         ## if absent, then args_list stays the same e.g. b="b", e="e"
         arguments <- list(...)
         modified_args_list <- amazing_function(arguments, args_list)
         return(modified_args_list)
         } 

    }
Run Code Online (Sandbox Code Playgroud)

args_list每次都会有所不同 - 它是一个在httr请求中发送的正文对象.

如果列表没有嵌套列表,我有一个有效的函数:

substitute.list <- function(template, replace_me){

  template[names(replace_me)] <- 
    replace_me[intersect(names(template),names(replace_me))]

  return(template)

}

t …
Run Code Online (Sandbox Code Playgroud)

functional-programming r nested-lists

11
推荐指数
1
解决办法
278
查看次数

在Shiny服务器中调用被动数据集的Shiny Module

我希望移植一些较旧的Shiny应用程序来使用Shiny Modules,但是在尝试移植我的反应式表达式时遇到了麻烦.

根据文件:

目标不是阻止模块与其包含的应用程序交互,而是使这些交互显式化.如果模块需要使用反应式表达式,请将反应式表达式作为函数参数.

我有现有的反应式表达式从API等导入我希望传递的数据,但似乎无法找到语法.如果我修改下面给出的Shiny模块示例,我可能会遇到同样的问题.

任何人都可以修改下面的内容,以便您可以将car_data()反应数据传入模块吗?我试过的几乎所有组合isolatecar_data/car_data()我能想到的和我难倒了:)

我宁愿不需要在模块本身内调用数据,因为在我的情况下,我正在尝试推广适用于大量数据集的ETL函数.

library(shiny)
library(ggplot2)

linkedScatterUI <- function(id) {
  ns <- NS(id)

  fluidRow(
    column(6, plotOutput(ns("plot1"), brush = ns("brush"))),
    column(6, plotOutput(ns("plot2"), brush = ns("brush")))
  )
}

linkedScatter <- function(input, output, session, data, left, right) {
  # Yields the data frame with an additional column "selected_"
  # that indicates whether that observation is brushed
  dataWithSelection <- reactive({
    brushedPoints(data(), input$brush, allRows = TRUE)
  })

  output$plot1 <- renderPlot({
    scatterPlot(dataWithSelection(), left()) …
Run Code Online (Sandbox Code Playgroud)

module r shiny

8
推荐指数
2
解决办法
3993
查看次数

使用HTTP设置Kuberentes集群RStudio和Shiny的负载平衡入口会导致错误页面

我正在尝试在Google Kubernetes Engine上创建一个运行nginx,RStudio服务器和两个Shiny应用程序的集群,遵循并修改本指南.

我有4个工作负载在UI中都是绿色的,通过以下方式部署:

kubectl run nginx --image=nginx --port=80
kubectl run rstudio --image gcr.io/gcer-public/persistent-rstudio:latest --port 8787
kubectl run shiny1 --image gcr.io/gcer-public/shiny-googleauthrdemo:latest --port 3838
kubectl run shiny5 --image=flaviobarros/shiny-wordcloud --port=80
Run Code Online (Sandbox Code Playgroud)

然后它们通过以下方式暴露为节点端口:

kubectl expose deployment nginx --target-port=80  --type=NodePort
kubectl expose deployment rstudio --target-port=8787  --type=NodePort
kubectl expose deployment shiny1 --target-port=3838  --type=NodePort
kubectl expose deployment shiny5 --target-port=80  --type=NodePort
Run Code Online (Sandbox Code Playgroud)

..在UI中都是绿色的.

然后我部署了这个Ingress后端

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: r-ingress
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: nginx
          servicePort: 80
      - path: /rstudio/ …
Run Code Online (Sandbox Code Playgroud)

rstudio-server kubernetes google-kubernetes-engine kubernetes-health-check

6
推荐指数
1
解决办法
780
查看次数

损坏的DAG:(...)没有名为docker的模块

我有所有运行的BigQuery连接器,但是我希望在Cloud Composer而不是App Engine Flexible上计划在Docker容器中有一些现有脚本。

我有以下脚本似乎遵循了我可以找到的示例:

import datetime
from airflow import DAG
from airflow import models
from airflow.operators.docker_operator import DockerOperator

yesterday = datetime.datetime.combine(
    datetime.datetime.today() - datetime.timedelta(1),
    datetime.datetime.min.time())

default_args = {
    # Setting start date as yesterday starts the DAG immediately
    'start_date': yesterday,
    # If a task fails, retry it once after waiting at least 5 minutes
    'retries': 1,
    'retry_delay': datetime.timedelta(minutes=5),
}

schedule_interval = '45 09 * * *'

dag = DAG('xxx-merge', default_args=default_args, schedule_interval=schedule_interval)

hfan = DockerOperator(
   task_id = 'hfan',
   image   = …
Run Code Online (Sandbox Code Playgroud)

directed-acyclic-graphs docker airflow google-cloud-composer

5
推荐指数
3
解决办法
2609
查看次数

无法从 Google Container VM 映像访问服务帐户的元数据令牌

我从此处详述的 VM 映像登录到 Google Compute Engine 实例。

我想按照有关访问私有容器注册表的说明进行操作,但在请求令牌时收到 403 错误。

试试这个:

$ METADATA=http://metadata.google.internal/computeMetadata/v1
$ SVC_ACCT=$METADATA/instance/service-accounts/default
$ ACCESS_TOKEN=$(curl -H 'Metadata-Flavor: Google' $SVC_ACCT/token \
    | cut -d'"' -f 4)
$ docker login -e 1234@5678.com -u _token -p $ACCESS_TOKEN https://gcr.io
$ docker run --rm gcr.io/<your-project>/<your-image> <command>
Run Code Online (Sandbox Code Playgroud)

..我没有找到访问令牌并且失败了。

尝试调用元数据我可以看到:

> curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/" -H "Metadata-Flavor: Google"

aliases
email
scopes
token
Run Code Online (Sandbox Code Playgroud)

...但是当我尝试获取令牌时,出现 403 错误:

> curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" -H "Metadata-Flavor: Google"

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 403 (Forbidden)!!1</title> …
Run Code Online (Sandbox Code Playgroud)

authentication metadata google-cloud-platform

4
推荐指数
1
解决办法
1万
查看次数

您能否将表示 RDS 文件的 R 原始向量转换回 R 对象,而无需往返磁盘?

我有一个已上传的 RDS 文件,然后通过curl::curl_fetch_memory()(via httr) 下载 - 这为我提供了 R 中的原始向量。

有没有办法读取表示 RDS 文件的原始向量以返回原始 R 对象?或者总是必须先将其写入磁盘?

我有一个类似于下面的设置:

saveRDS(mtcars, file = "obj.rds")
# upload the obj.rds file 
...
# download it again via httr::write_memory()
...

obj
#   [1] 1f 8b 08 00 00 00 00 00 00 03 ad 56 4f 4c 1c 55 18 1f ca 02 bb ec b2 5d 
# ...
is.raw(obj)
#[1] TRUE
Run Code Online (Sandbox Code Playgroud)

它似乎readRDS()应该用于解压缩它,但它需要一个连接对象,而且我不知道如何从 R 原始向量创建连接对象 -rawConnection()看起来很有希望,但给出了:

rawConnection(obj)
#A connection with                           
#description …
Run Code Online (Sandbox Code Playgroud)

r rcurl httr raw

4
推荐指数
1
解决办法
563
查看次数

尝试将图像添加到极坐标图会给出“错误:annotation_custom 仅适用于笛卡尔坐标”

我已经尝试按照已经给出答案将图像添加到绘图中,但是它们在使用时不起作用coord_polar()

# install.packages("RCurl", dependencies = TRUE)
library(RCurl)
myurl <- "http://vignette2.wikia.nocookie.net/micronations/images/5/50/German_flag.png"

# install.packages("png", dependencies = TRUE)
library(png)
img <-  readPNG(getURLContent(myurl))

# install.packages("ggplot2", dependencies = TRUE)
library(ggplot2)

ger <- grid::rasterGrob(img, interpolate=TRUE)

## works, adds the image to the plot
ggplot(mtcars, aes(x=mpg, y= cyl)) + geom_line() + annotation_custom(ger, 10, 15, 5)

## doesn't work
ggplot(mtcars, aes(x=mpg, y= cyl)) + geom_line() + annotation_custom(ger) + coord_polar()
> Error: annotation_custom only works with Cartesian coordinates
Run Code Online (Sandbox Code Playgroud)

理想情况下,我希望能够将标志图像定位在极坐标图的中心,并沿着 y 轴定位另一个图像。

无论如何要添加图像?它可以原样,无需转换。

我正在使用ggplot2 …

r ggplot2

3
推荐指数
1
解决办法
2373
查看次数