【发布时间】:2019-02-15 08:28:14
【问题描述】:
我在使用 RHandsontable(版本:0.3.6)时遇到了一个特殊问题。我面临的问题与 UI 输入的转换有关。当输入数字 (x) 时,它们被正确存储。但是,当输入百分比 (x%) 时,除零百分比(0%、0.0%、0.00% 等)之外的所有值都将正确存储。 Zeroeth Percents 转换为 NULL 值,从 excel 下载中可见。
附上观察到的行为的可重现示例。
library(shiny)
library(openxlsx)
library(rhandsontable)
ui <- fluidPage(
br(),
rHandsontableOutput("table"),
br(),
downloadButton("download","Download"))
server <- function(input, output, session) {
output$table <- renderRHandsontable({
df <- data.frame("Growth" = c(0.1,0.02,0.06,0.24,0.08))
rhandsontable(df, rowHeaders = NULL,colHeaders = c("Growth")) %>%
hot_col(c("Growth"), format = "0.0%") %>%
hot_validate_numeric(cols = c(1),min = 0.00, max = 1.00)
})
output$download <- downloadHandler(
filename = function() {
paste('Report.xlsx')
},
content <- function(file) {
write.xlsx(hot_to_r(input$table),file)
})
}
shinyApp(ui, server)
需要在 UI 中更改输入,而不是代码本身。您可以尝试在 UI 中输入 0%(not 0)作为输入,它会在 excel 提取中生成 NULL 值,其中插入了“0%”、“0.0%”等。您可以通过下载 excel 提取来验证我的发现。这是与包相关的问题还是与此代码相关?如果以后有任何调试指针表示赞赏。
【问题讨论】:
-
我无法重现这个问题,我给了
df <- data.frame("Growth" = c(0,0.02,0.06,0.24,0.08)),输出给了 0 -
@amrrs 可能我的问题没有说清楚。需要在 UI 中更改输入,而不是代码本身。您可以尝试在 UI 中输入 0%(不是 0)作为输入,它会在 excel 提取中生成 NULL 值,其中插入了 0%、0.0% 等。
-
我认为这很可能是因为它无法将 0% 转换为十进制,因此在使用
hot_to_r()进行转换时变为 NA
标签: shiny handsontable rhandsontable