我想知道在使用rhandsontable函数时,如何将千位分隔符改为点,将小数分隔符改为逗号。
下面是一个可重复的小例子。
library(tidyverse)
library(shiny)
library(shinydashboard)
library(rhandsontable)
data_test <- iris
ui <- dashboardPage(
skin = "black",
dashboardHeader(
title = "Test",
titleWidth = 100
),
dashboardSidebar(collapsed = TRUE),
dashboardBody(
fluidRow(column(
width = 3,
selectInput(
inputId = "specie",
label = "Specie",
choices = unique(data_test$Species),
multiple = FALSE
)),
rHandsontableOutput("rTable")))
)
server <- function(input, output, session) {
rv <- reactiveValues(table1 = NULL)
observeEvent(input$specie,{
data <- data_test %>%
filter(Species == input$specie) %>%
mutate(Sepal.Length2 = 0,
Sepal.Width2 = 0,
Petal.Length2 = 0,
Petal.Width2 = 0,
amount = 50,
percentage = 100) %>%
select(1:4,6:11)
rv$table1<- data})
observe({
if (!is.null(input$rTable)){
mytable <- as.data.frame(hot_to_r(input$rTable))
mytable[,7] <- mytable[,5]*100
mytable[,8] <- mytable[,6]*100
numberofrows <- nrow(mytable)
rv$table1 <- mytable}
})
output$rTable <- renderRHandsontable({
rhandsontable(rv$table1) %>%
hot_col("Sepal.Length", format = "0.0,0") %>%
hot_col("Sepal.Width", format = "0.0,0") %>%
hot_col("Petal.Length", format = "0.0,0") %>%
hot_col("Petal.Width", format = "0.0,0") %>%
hot_col("Sepal.Length2", format = "0.0,0") %>%
hot_col("Sepal.Width2", format = "0.0,0") %>%
hot_col("Petal.Length2", format = "0.0,0") %>%
hot_col("Petal.Width2", format = "0.0,0") %>%
hot_col("amount", format = "$0.0,0") %>%
hot_col("percentage", format = "0,0") %>%
hot_cols(colWidths = 130)
})
}
shinyApp(ui = ui, server=server)
我尝试了hot_col函数,但这并不能解决我的问题,我也尝试了其他函数,如prettyNum,format,formatC等,但我也不能解决它。任何帮助都非常感谢。
1条答案
按热度按时间wn9m85ua1#
我将使用d3.format库,如下所示: