Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:formattable';s样式参数';输出图片上显示的内容_R_Formattable - Fatal编程技术网

R:formattable';s样式参数';输出图片上显示的内容

R:formattable';s样式参数';输出图片上显示的内容,r,formattable,R,Formattable,给出如下数据帧: df <- structure(list(` ` = c("v1", "v2", "v3", "v4", "v5", "v5", "v6", "v7", "v8", "v9", "v10"), last_we

给出如下数据帧:

df <- structure(list(` ` = c("v1", "v2", "v3", "v4", "v5", "v5", "v6", "v7", "v8", 
                       "v9", "v10"), last_week = c(10, 31.34, 85.86, 
3375.01, 7721.54, 9, 18.28, 58.84, 6177.73, 19890.55, 36.35), 
    this_week = c(27, 47.25, 99.4, 2253.04, 4861.4, 20, 43.04, 52.89, 
    2395.22, 2943.64, 12.67), pct = structure(c(1.7, 0.5077, 
    0.1577, -0.3324, -0.3704, 1.2222, 1.3545, -0.1011, -0.6123, 
    -0.852, -0.6515), formattable = list(formatter = "formatC", 
        format = list(format = "f", digits = 2L), preproc = "percent_preproc", 
        postproc = "percent_postproc"), class = c("formattable", 
    "numeric"))), class = "data.frame", row.names = c(NA, -11L
))
输出:

但正如您所看到的,
本周
上周
列不是常规数字

它以前已经解决了,但在我更新包之后似乎出现了错误


谁知道我该如何处理这个问题?谢谢。

我通过更改格式化程序参数changing~ by df=,解决了您的问题:

formattable(df,
            list(
              df=formatter("span",
                         style = x ~ formattable::style(display = "block",
                                                        "border-radius" = "2px",
                                                        "padding" = "2px",
                                                        "text-align" = "left")
              ),
              last_week = color_tile("#DeF7E9", "#FA614B"),
              this_week = color_tile("#DeF7E9", "#FA614B"),
              `pct` = formatter("span",
                                style = ~ style(color = ifelse(`this_week` > `last_week`, "red", "green")),
                                ~ icontext(sapply(`pct`, function(x) if (x < 0) "arrow-down" else if (x > 0) "arrow-up" else ""), `pct`)))
)
formattable(df,
名单(
df=格式化程序(“span”,
style=x~formattable::style(display=“block”,
“边界半径”=“2px”,
“padding”=“2px”,
“文本对齐”=“左”)
),
上周=彩色瓷砖(“#DeF7E9”和“#FA614B”),
本周=彩色瓷砖(“DeF7E9”和“FA614B”),
`pct`=格式化程序(“span”,
style=~style(color=ifelse(`this_week`>`last_week`,`red','green”),
~icontext(sappy(`pct`,函数(x)if(x<0)“向下箭头”else if(x>0)“向上箭头”else“”,`pct`))
)

谢谢,如果我评论格式化程序(“span”,style=x~formattable::style(display=“block”,“border radius”=“2px”,“padding”=“2px”,“text align”=“left”)),它似乎也能起作用。。
formattable(df,
            list(
              df=formatter("span",
                         style = x ~ formattable::style(display = "block",
                                                        "border-radius" = "2px",
                                                        "padding" = "2px",
                                                        "text-align" = "left")
              ),
              last_week = color_tile("#DeF7E9", "#FA614B"),
              this_week = color_tile("#DeF7E9", "#FA614B"),
              `pct` = formatter("span",
                                style = ~ style(color = ifelse(`this_week` > `last_week`, "red", "green")),
                                ~ icontext(sapply(`pct`, function(x) if (x < 0) "arrow-down" else if (x > 0) "arrow-up" else ""), `pct`)))
)