Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.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 带逗号的闪亮可渲染_R_Shiny - Fatal编程技术网

R 带逗号的闪亮可渲染

R 带逗号的闪亮可渲染,r,shiny,R,Shiny,在我的闪亮包中,我有以下代码: output$growthTable <- renderTable({ table <- makeTable() colnames(table) <- c("Year","BOY Balance", "Yearly Growth", "EOY Contribution", "EOY Balance") return(table) }, include.rownames = FALSE) 如何使最后4列中有逗号。比如说10000变成1

在我的闪亮包中,我有以下代码:

output$growthTable <- renderTable({
  table <- makeTable()
  colnames(table) <- c("Year","BOY Balance", "Yearly Growth", "EOY Contribution", "EOY Balance")
  return(table)
}, include.rownames = FALSE)

如何使最后4列中有逗号。比如说10000变成10000

由于您没有提供一个可复制的示例,这里是一个如何进行的工作演示。据我所知,无法使用renderable语句指定数字格式,因此必须重新设置值的格式。关键是将format或prettyNum与big.mark选项集一起使用。但是,需要注意的是,这是将数值转换为字符。建议您在不再对值进行进一步处理后进行此格式转换

require(shiny)
data(iris)

runApp(
  list(
    ui = fluidPage(
      headerPanel('Print big numbers with comma'),
      mainPanel(
        tableOutput("table"))
    ),

    server = function(input, output) {

      makeTable <- reactive({
        iris[,1:4] <- iris[1:4] * 1000
        #iris[,1:4] <- sapply(iris[,1:4], FUN=function(x) format(x, big.mark=","))
        iris[,1:4] <- sapply(iris[,1:4], FUN=function(x) prettyNum(x, big.mark=","))
        iris
      })

      output$table <- renderTable({
        table <- makeTable()
        table
      }, include.rownames = FALSE)
    }
  )
)

因为你没有提供一个可复制的例子,这里是一个如何做的工作演示。据我所知,无法使用renderable语句指定数字格式,因此必须重新设置值的格式。关键是将format或prettyNum与big.mark选项集一起使用。但是,需要注意的是,这是将数值转换为字符。建议您在不再对值进行进一步处理后进行此格式转换

require(shiny)
data(iris)

runApp(
  list(
    ui = fluidPage(
      headerPanel('Print big numbers with comma'),
      mainPanel(
        tableOutput("table"))
    ),

    server = function(input, output) {

      makeTable <- reactive({
        iris[,1:4] <- iris[1:4] * 1000
        #iris[,1:4] <- sapply(iris[,1:4], FUN=function(x) format(x, big.mark=","))
        iris[,1:4] <- sapply(iris[,1:4], FUN=function(x) prettyNum(x, big.mark=","))
        iris
      })

      output$table <- renderTable({
        table <- makeTable()
        table
      }, include.rownames = FALSE)
    }
  )
)

这太棒了,正是我需要的:-。这太棒了,正是我需要的:-。