Auto-rounding to 2 digits when rendering a table

931 views
Skip to first unread message

Dimitri Liakhovitski

unread,
Sep 19, 2014, 11:33:19 AM9/19/14
to shiny-...@googlegroups.com
Hello!

My function is returning a data frame with numbers. And those numbers are not rounded.
I just return this data frame.

In my server.R I want to show this data frame (as a table) and I say:

 output$RegResults<-renderTable({
   if(is.null(input$file1)){return()}
   outdata<-PAout()$outtab
   outdata
 })

I want to return it for the user on my 2nd tab ("Output Summary") so that my ui.r says:

  mainPanel(
    tabsetPanel(
      tabPanel(...bla-bla...),
      tabPanel("Output Summary",
               h4(textOutput("caption2")),
               tableOutput("RegResults"),
               value=2),
      tabPanel(...bla-bla...),id='tabpanel'
      
    )
  )))

Everything works, but all the entries in the table ("RegResults") are rounded to 2 digits. I'd like some of the columns to have 3 digits. Or, if that's impossible, I'd like all numbers to have 3 digits after the comma.
Thanks a lot for your help!

Dimitri Liakhovitski

unread,
Sep 19, 2014, 4:13:10 PM9/19/14
to shiny-...@googlegroups.com
I found a partial answer (rounds everything in the table to 3 digits):

  output$RegResults<-renderTable({
    if(is.null(input$file1)){return()}
    outdata<-PAout()$outtab
    outdata
  },digits=3)

Lawrence Lin

unread,
Feb 5, 2016, 11:52:05 AM2/5/16
to Shiny - Web Framework for R
I have the same problem.  I used your suggestion and still render everything with 2 significant digits.  Can someone help?  Thanks!

Giovanni Iacopetti

unread,
Nov 23, 2017, 5:30:31 PM11/23/17
to Shiny - Web Framework for R
Just in case somebody will search it again: to set "digits = 0", solve the problem.
Reply all
Reply to author
Forward
0 new messages