4

I have a DataTable that is displaying perfectly in my Shiny application except for the thousands separator, which is not displaying at all. I figured it would use a comma by default, but when it was not showing I tried to specify it using oLanguage sInfoThousands. My other oLanguage specification sInfo is working, so I am trying to figure out why no thousands separator is showing at all. Does this seem like a data type issue or an issue with how I've specified it? The first two columns are strings in both tables, and the rest are integers (in the dataframe they are doubles) which are sorting appropriately.

shinyServer(function(input, output, session){
  tab1_final<-read.csv("/home/bdk/tracker/tab1_final.csv")
  tab2_final<-read.csv("/home/bdk/tracker/tab2_final.csv")

  mydata <- reactive({
    switch(input$dataset, FY = data.table(tab2_final),
           Q = data.table(tab1_final)                     
    )
  })

  output$mytable <- renderChart2({
    dTable(mydata(), 
           sPaginationType = 'full_numbers',
           aLengthMenu = list(c(10, 25, 50, 100, -1),c(10, 25, 50, 100, "All")),
           oLanguage = list(sInfo="Showing _START_ to _END_ of _TOTAL_ entries. All numbers shown in US Dollars.",
                            sInfoThousands=","
                            )
           )
  })
})

Thanks for the help, and let me know if I should provide any more info. (first question posted, so sorry if I've violated any rules!)

Edit (with mtcars--I multplied mpg so that it should require a thousands separator):

#server.R
require(rCharts)
shinyServer(function(input, output, session){
  mtcars$mpg<-mtcars$mpg*1000.3
  mydata <- reactive({
    switch(input$dataset, By_Fiscal_Year = data.table(mtcars),
           By_Quarter = data.table(mtcars)                     
    )
  })
  output$mytable <- renderChart2({
    dTable(data.table(mydata()), 
           sPaginationType = 'full_numbers',
           aLengthMenu = list(c(10, 25, 50, 100, -1),c(10, 25, 50, 100, "All")),
           oLanguage = list(sInfoThousands=",")
           )
  })
})

#ui.R
require(shiny)
require(shinyIncubator)
require(rCharts)
options(RCHART_LIB = 'polycharts')
shinyUI(pageWithSidebar(
  headerPanel(list('Test DataTables Comma')),
  sidebarPanel(  
    selectInput('dataset', 'Choose Current Quarter or Entire FY',
                c('By_Fiscal_Year', 'By_Quarter')            
    )
  ),
  mainPanel(
    tabsetPanel(id ="tab1",
      tabPanel("Table", chartOutput("mytable", "datatables"))
    )
  )
))

How do I get a comma to appear in the mpg column yet still have it sort as a number? I don't have the reputation yet to post an image, but here is a link to a screenshot of what I am seeing (first column has no thousands separator):

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
bkauder
  • 123
  • 1
  • 9
  • Hi and welcome to SO. Could you post the output you are getting, vs. what you are expecting? Also, are you using rCharts in addition to Shiny? Rather than tab1_final.csv (which we don't have) if you can post a reproducible example using mtcars or other built-in datasets, someone here will be able to help you. – Ram Narasimhan Jan 03 '14 at 18:18
  • thanks Ram, I have edited for an example with mtcars – bkauder Jan 03 '14 at 22:11
  • Your code seems okay to me. The gist that @ramnathv has provided doesn't cover the thousands separator. You could ask for help in rCharts github, and he might be able to help you. – Ram Narasimhan Jan 05 '14 at 02:57
  • Possible duplicate of [Control number formatting in Shiny's implementation of DataTable](https://stackoverflow.com/questions/27255108/control-number-formatting-in-shinys-implementation-of-datatable) – mschilli Nov 26 '18 at 15:55

0 Answers0