我使用 rhandsotable 库创建了一个简单的表,无论我如何格式化它,数字总是向下或向上舍入到最接近的整数。例如,如果我输入 1.02,显示的结果为 1。对于 0.46,显示的结果为 0。我尝试将数字设为双精度格式,但问题仍然存在。. 请告知如何解决此问题。谢谢你。
library(shiny)
library(rhandsontable)
GM <- data.frame(matrix(0.0, ncol = 5, nrow = 3))
col_names <- c("2015", "2016", "2017", "2018", "2019")
row_names <- c("Worst", "Base", "Best")
colnames(GM) <- col_names
rownames(GM) <- row_names
ui <- fluidPage(
titlePanel("GM"),
mainPanel(
rHandsontableOutput("GM"))
)
server <- function(input, output) {
v = reactiveValues()
observe({input$GM
if (!is.null(input$GM)) {
v$GM <- hot_to_r(input$GM)
print(v$GM) # to see if values get rounded down
} else {
v$GM <- GM
}
})
output$GM <- renderRHandsontable({
rhandsontable(v$GM, rowHeaderWidth = 150) %>%
hot_col("2015", format = "0,0.00%") %>%
hot_col("2016", format = "0,0.00%") %>%
hot_col("2017", format = "0,0.00%") %>%
hot_col("2018", format = "0,0.00%") %>%
hot_col("2019", format = "0,0.00%") %>%
hot_cols(colWidths = 100) %>%
hot_rows(rowHeights = 30)
})
}
shinyApp(ui = ui, server = server)