标签: formattable

String,FormattableString,IFormattable之间的区别

FormattableString已在C#6.0中引入.因为我们可以使用相同的字符串格式使用string对象为什么需要使用FormattableStringIFormattable.三者之间有什么区别?

我的守则

        var name = "Pravin";
        var s = $"Hello, {name}";
        System.IFormattable s1 = $"Hello, {name}";
        System.FormattableString s2 = $"Hello, {name}";
Run Code Online (Sandbox Code Playgroud)

最重要的是产生相同的结果.即'Hello Pravin'.

如果有人对此有深入的了解,我能否得到更详细的答案.

c# string iformattable formattable formattablestring

37
推荐指数
2
解决办法
9793
查看次数

使用Format-Table控制列宽

我试图从列表中获取一些PC的最后重启时间.我用的时候

foreach ($pc in $pclist) {
  Get-CimInstance -ClassName win32_operatingsystem -ComputerName $pc |
    select csname, lastbootuptime 
}
Run Code Online (Sandbox Code Playgroud)

输出如下.

csname       lastbootuptime
------       --------------
CONFA7-L1-1A 7/15/2016 9:55:16 AM
CONFA7-L1-1F 5/31/2016 8:51:46 AM
CONFA7-L1-1G 6/18/2016 11:09:15 AM
CONFA7-L1... 6/26/2016 5:31:31 PM
CONFA7-L3... 7/24/2016 3:48:43 PM

哪个很整洁,但如果PC名称很长,我无法看到全名.所以我流水线Format-Table:

Get-CimInstance -ClassName win32_operatingsystem -ComputerName $pc |
  select csname, lastbootuptime |
  Format-Table  -HideTableHeaders 
Run Code Online (Sandbox Code Playgroud)

这就是我得到的:

CONFA7-L1-1A 7/15/2016 9:55:16 AM



CONFA7-L1-1E 7/21/2016 12:58:16 PM



CONFA7-L1-1F 5/31/2016 8:51:46 AM

这里有两个问题.

  1. 没有标题.如果我删除-HideTableHeaders将有标题为每个输出不需要.

  2. 中间有很多空白区域.

基本上我只需要获得类似于第一个的输出,但不要截断全名.我该如何解决这些问题?

powershell formatting formattable

13
推荐指数
2
解决办法
3万
查看次数

如何在闪亮的仪表板中使用R包"formattable"?

以下是我编写的代码.我无法使用formattable我的光泽.formattable有助于格式化表格并改善可视化效果.

library("shinydashboard")
library("shiny")
library("formattable")

body <- dashboardBody(
  fluidRow(
    column(width = 12,
           box(tableOutput(formattable(test.table, list())))
           )
    )
  )

ui <- dashboardPage(
  dashboardHeader(title = "Column layout"),
  dashboardSidebar(),
  body
)

server <- function(input, output) {

  test.table <- data.frame(lapply(1:8, function(x) {1:10}))

    output$table <- renderTable({test.table})
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

r shiny formattable

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

java.util.Formattable上的示例是否不正确?

使用给出java.util.Formattable示例(修改为实际设置构造函数中的值),事情似乎正常工作:

import java.nio.CharBuffer;
import java.util.Formatter;
import java.util.Formattable;
import java.util.Locale;
import static java.util.FormattableFlags.*;

public class StockName implements Formattable {
    private String symbol, companyName, frenchCompanyName;
    public StockName(String symbol, String companyName,
                     String frenchCompanyName) {
        this.symbol = symbol;
        this.companyName = companyName;
        this.frenchCompanyName = frenchCompanyName;
    }

    public void formatTo(Formatter fmt, int f, int width, int precision) {
        StringBuilder sb = new StringBuilder();

        // decide form of name
        String name = companyName;
        if (fmt.locale().equals(Locale.FRANCE))
            name = frenchCompanyName;
        boolean alternate …
Run Code Online (Sandbox Code Playgroud)

java formatting formatter formattable

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

在R中使用formattable时打印空白而不是NA

考虑示例data.frame

df <- data.frame(
  id = 1:4,
  name = c("Bob", "Ashley", "James", "David"), 
  age = c(48, NA, 40, 28),
  test1_score = c(18.9, 19.5, NA, 12.9),
  stringsAsFactors = FALSE)
Run Code Online (Sandbox Code Playgroud)

我正在使用R包格式化表来创建一个漂亮的表.

library(formattable)
formattable(df, list(
age = color_tile("white", "orange"),
test1_score = color_bar("pink", 'proportion', 0.2)
))
Run Code Online (Sandbox Code Playgroud)

过去,NA会自动不打印,而是打印出一个空白.看起来这不再是默认设置,但我还是想为NA打印一个空白.像这样替换NA有效:

df[is.na(df)]=''
formattable(df, list(
  age = color_tile("white", "orange"),
  test1_score = color_bar("pink", 'proportion', 0.2)
))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但是,如果我尝试格式化其中一个列以强制它有2个小数位,那么麻烦的NA会返回:

df$age = digits(df$age, digits=2)
formattable(df, list(
age = color_tile("white", "orange"),
test1_score = color_bar("pink", 'proportion', 0.2)
))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如果我再次移除NA,则NA会消失,但小数位也会消失

df[is.na(df)] = ''
formattable(df, list(
age …
Run Code Online (Sandbox Code Playgroud)

r formattable

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

用R中的Formattable软件包制作的导出/保存表的命令

https://cran.r-project.org/web/packages/formattable/formattable.pdf

我一直在使用Formattable包在R中制作一些漂亮的表。我试图将这些表另存为图像(或实际上任何文件格式),但找不到有效的命令。使用jpeg / png函数或dev.copy创建空白文档。理想情况下,我希望能够将这些表循环保存。有谁知道该怎么做?

数据:

library(formattable)
DF <- data.frame(Ticker=c("", "", "", "IBM", "AAPL", "MSFT"),
                 Name=c("Dow Jones", "S&P 500", "Technology", 
                        "IBM", "Apple", "Microsoft"),
                 Value=accounting(c(15988.08, 1880.33, NA, 
                                    130.00, 97.05, 50.99)),
                 Change=percent(c(-0.0239, -0.0216, 0.021, 
                                  -0.0219, -0.0248, -0.0399)))

formattable(DF, list(
  Name=formatter(
    "span",
    style = x ~ ifelse(x == "Technology", 
                       style(font.weight = "bold"), NA)),
  Value = color_tile("white", "orange"),
  Change = formatter(
    "span",
    style = x ~ style(color = ifelse(x < 0 , "red", "green")),
    x ~ icontext(ifelse(x < 0, "arrow-down", "arrow-up"), x)))
)
Run Code Online (Sandbox Code Playgroud)

export r save formattable

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

使用 Formattable R 的条件格式

我有一个看起来像的数据框:

   from   to  value sourceID targetID clustid
1  1400 1413 0.6846  3055586  3060697       1
2   323  661 0.5550  1596205   724084       1
3   323 1411 0.6817   724084  3060607       1
4  1413 1411 0.6729  3060697  3060607       1
5  1498 1411 0.6381  3111960  3060607       1
6  1478 1415 0.7423  3062164  3099199       2
7  1478 1414 0.7423  3099199  3062163       2
8  1415 1462 0.7078  3090708  3062164       2
9  1415 1463 0.7078  3062164  3090709       2
10 1462 1404 0.7078  3090708  3058341       2
11 1418  278 …
Run Code Online (Sandbox Code Playgroud)

r html-table formattable

5
推荐指数
0
解决办法
1331
查看次数

如何使用formattable折叠表中的行值组?

我对使用formattableR 包中的工具感兴趣,但我只想在表中显示有变化的地方。也就是说,我想要kableExtra通过collapse_rows()函数在包中提供的分层行标签。

例如,使用kable()and kableExtra,我可以这样做:

library(dplyr)
library(knitr)
library(kableExtra) 

iris %>% 
  group_by(Species) %>% 
  slice(1:2) %>% 
  select(Species, everything()) %>% 
  kable() %>% 
  collapse_rows(1, valign="top")
Run Code Online (Sandbox Code Playgroud)

产生这个:

带有按物种分组的行的鸢尾花表

但是,我想使用formattable包和函数来执行此操作,以便我可以在输出期间在特定列上运行任意函数。具体来说,我想添加“迷你图”作为新列。我可以使用knitrand做到这一点formattble,但collapse_rows据我所知,我失去了。

有什么办法可以折叠行formattable吗?

r r-markdown formattable

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

可格式化对象的粗体行名称

这是我正在使用的格式化对象的最小示例:

library(formattable)
formattable(mtcars, 
            align = "c",
            list(~ formatter("span",
                             style = x ~ formattable::style(display = "block",
                                                            "border-radius" = "2px",
                                                            "padding" = "5px",
                                                            "text-align" = "center"))))
Run Code Online (Sandbox Code Playgroud)

如何修改它以加粗行名称?

r shiny formattable

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

R- 如何将 html 格式添加到与blastula一起使用的表格中?

Blastula 似乎不尊重表格格式化包(如和 )<style>使用的标签。kableextraformattable

例子:

library(kableExtra)
library(blastula)

dt <- mtcars[1:5, 1:6]

tbl <- dt %>%
  kbl() %>%
  kable_styling()

tbl

compose_email(
  body = md(c(
    "this is my table:",
    tbl
    )))
Run Code Online (Sandbox Code Playgroud)

打印 tbl 时显示此内容

在此输入图像描述

但是打印的时候是这样compose_email

在此输入图像描述

我认为这是因为blastula只是打印表格,并且kableextra格式在其他地方使用class

tbl <- dt %>%
  kbl("html")

tbl_styled <- tbl %>%
  kable_styling()

as.character(tbl)
as.character(tbl_styled)
Run Code Online (Sandbox Code Playgroud)

这表明打印样式表时唯一的区别是标签<table>

<table class=\"table\" style=\"margin-left: auto; margin-right: auto;\">
Run Code Online (Sandbox Code Playgroud)

所以我想唯一的方法是编写我们自己的表解析器来将样式内联?除非已经有一个 R 包可以做到这一点?

html r formattable kableextra blastula

5
推荐指数
0
解决办法
897
查看次数