小编Pau*_*eux的帖子

Docker版本18.04.0-ce会忽略不支持的选项:network_mode

对于一个小项目,我希望Docker容器中的应用程序连接到计算机的本地主机。这个问题的答案:从Docker容器内部,如何连接到计算机的本地主机?告诉我首选的方法是--net="host"在docker run命令中使用。

我使用撰写文件来启动容器。而这个问题对我的net选项被重命名为network_mode: "host"

这是撰写文件的开头

version: '3.6'
services:
  shiny:
    image: paulrougieux/eutradeflows
    deploy:
      restart_policy:
        condition: on-failure
    network_mode: "host"
    ports:
      - "3838:3838"
Run Code Online (Sandbox Code Playgroud)

当我启动这个文件时

 sudo docker stack deploy -c stackshiny.yml shiny
Run Code Online (Sandbox Code Playgroud)

我得到错误:

Ignoring unsupported options: network_mode
Run Code Online (Sandbox Code Playgroud)

有关信息

$ sudo docker version
Client:
 Version:   18.04.0-ce
Server:
 Engine:
  Version:  18.04.0-ce
Run Code Online (Sandbox Code Playgroud)

如何启用从Docker容器到主机上数据库的连接?

shiny docker docker-compose

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

如何使用 purrr 和 tidyr 修改嵌套数据框中的列类型

我正在将许多源文件中的数据读取到嵌套数据框中。某些列具有不兼容的数据类型,这会阻止tidyr::unnest()函数工作。

例如,这是一个基于iris数据集的嵌套数据框:

irisnested <- iris %>% 
    rename_all(tolower) %>% 
    group_by(species) %>% 
    nest()
Run Code Online (Sandbox Code Playgroud)

为了重现我的问题,我data在嵌套数据框的列表列中的子数据框之一中更改了列类型:

irisnested$data[[2]]$sepal.length <- as.character(irisnested$data[[2]]$sepal.length)
Run Code Online (Sandbox Code Playgroud)

现在数据框不能再取消嵌套了:

irisnested %>% 
    unnest(data)
# Error in bind_rows_(x, .id) : Column `sepal.length` can't be converted from numeric to character
Run Code Online (Sandbox Code Playgroud)

为了更正每个嵌套数据框中的列类型,我使用了一个匿名函数:

irisnested %>% 
    mutate(data = map(data,
                      function(dtf){
                          dtf$sepal.length = as.numeric(dtf$sepal.length)
                          return(dtf)
                      })) %>% 
    unnest(data)
Run Code Online (Sandbox Code Playgroud)

现在可以再次取消嵌套数据框。但是这个匿名函数看起来很复杂,我的直觉是肯定有另一种方法可以做到这一点。有没有更好的方法来执行此修改,例如使用modify_at

r tidyr purrr tidyverse

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

如何在 ggplot facet_wrap 文本中添加数学符号?

这个问题解释了如何在图中添加数学符号。但是当文本应该存储在数据框本身中时,这不起作用。出现在 facet_wrap 子图的小框中的文本就是这种情况。

这是一个可重现的示例。例如,假设我有 T 和 m³ 的数据,并且我想绘制这样的图。

library(ggplot2)
dtf <- data.frame(year = rep(1961:2010,2),
                  consumption = cumsum(rnorm(100)),
                  item = rep(c("Tea bags","Coffee beans"),each=50),
                  unit = rep(c("T","m^3"),each=50))
ggplot(data=dtf)+
    geom_line(aes(x=year, y=consumption),size=1) +
    ylab(expression(paste("Consumption in T or ",m^3))) +
    scale_x_continuous(breaks = seq(1960,2010,10)) +
    theme_bw() + facet_wrap(item~unit, scales = "free_y")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

ylab(expression(m^3))正确显示单位。我怎么能在 facet 中显示类似的 m³?

r ggplot2 facet-wrap

2
推荐指数
1
解决办法
1131
查看次数

为什么 numpy.vectorize() 改变标量函数的除法输出?

当我用 numpy 对函数进行向量化时,我得到了一个奇怪的结果。

import numpy as np
def scalar_function(x, y):
    """ A function that returns x*y if x<y and x/y otherwise
    """
    if x < y :
        out = x * y 
    else:
        out = x/y 
    return out

def vector_function(x, y):
    """
    Make it possible to accept vectors as input
    """
    v_scalar_function = np.vectorize(scalar_function)
    return v_scalar_function(x, y)
Run Code Online (Sandbox Code Playgroud)

我们确实有

scalar_function(4,3)
# 1.3333333333333333
Run Code Online (Sandbox Code Playgroud)

为什么矢量化版本会给出这种奇怪的输出?

vector_function(np.array([3,4]), np.array([4,3]))
[12  1]
Run Code Online (Sandbox Code Playgroud)

虽然对矢量化版本的调用工作正常:

vector_function(np.array([4,4]), np.array([4,3]))
[1.         1.33333333]
Run Code Online (Sandbox Code Playgroud)

阅读numpy.divide

注释 Python 2.2 中添加了向下除法运算符 //,使 // …

python numpy division

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

标签 统计

r ×2

division ×1

docker ×1

docker-compose ×1

facet-wrap ×1

ggplot2 ×1

numpy ×1

purrr ×1

python ×1

shiny ×1

tidyr ×1

tidyverse ×1