2

I created a simple table using rhandsotable library and no matter how I format it, number always gets rounded down or up to closest integer. For example, if I type in 1.02, the result shown is 1. For 0.46, result shown is 0. I tried getting numbers to be double format, but issue persists. . Please kindly advise how to solve this issue. Thank you.

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)
Martin
  • 133
  • 13
  • Your example does not work for me, I get an error. Please see [here](https://stackoverflow.com/questions/48343080/how-to-convert-a-shiny-app-consisting-of-multiple-files-into-an-easily-shareable/48343110#48343110) for tips on how to create and format a good Shiny reproducible example. – Florian Jul 17 '18 at 06:29
  • Hi! Thanks for heads up and link. I added working code example. Please kindly advise on the issues regarding number rounding and error "attempt to select less than one element in get1index" if hot_col lines are used in the program. Thank you. – Martin Jul 17 '18 at 06:46
  • That looks better ;) about your error; for starters `hot_col` seems to indicate formatting of a column, while the arguments you use there seem to be the rownames? – Florian Jul 17 '18 at 06:49
  • Ups true. I fixed that and one error is gone. Now only number formatting issue still persists. Please advise how to solve it. Thank you. – Martin Jul 17 '18 at 07:09
  • If you enter `0.0046`, it will give you `0.46%`. – MLavoie Jul 21 '18 at 10:05
  • Try typing 0.46, 0.57 and then after you type 1 everything else becomes zero! Why is that? – Martin Jul 25 '18 at 18:06

0 Answers0