R在Rhansontable中的Shiny数字格式问题

时间:2018-07-17 06:24:41

标签: r shiny rhandsontable

我使用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)

0 个答案:

没有答案