gvisTables not rendering in Shiny apps

2020-04-10 00:00发布

The actual issue I'm trying to solve: I'm creating a dashboard which will include data tables. I would like for numbers to be formatted with commas as thousands separators, but there is (apparently) an issue with the DT package when it's used with Shiny, in that the comma-separated formatting causes DT::renderDataTable to read in numbers as character, which affects how the numbers are sorted. (DT's number formatting functionality does not work with Shiny, it appears.)

Where I'm at so far: The only solution I've been able to find is to use googleVis instead of DT to create the tables. Now I'm running into a different issue (described below), but what I really care about is having data tables with comma-separated numbers that sort like numbers.

The GoogleVis issue: When I use gvisTable outside of Shiny apps, they render perfectly fine, but they do not render at all when using renderGvis and htmlOutput in Shiny. As an example, I'll borrow Example 4 from here.

Not using Shiny, my code looks like this:

library(datasets)
library(googleVis)

myOptions <- list(page='enable', pageSize=10, width=550)

Table <- gvisTable(Population,options=myOptions)

plot(Table)

Using Shiny, it's like this:

library(datasets)
library(googleVis)
library(shiny)

shinyApp(
  ui = pageWithSidebar(
    headerPanel("Example 4: pageable table"),
    sidebarPanel(
      checkboxInput(inputId = "pageable", label = "Pageable"),
      conditionalPanel("input.pageable==true",
                       numericInput(inputId = "pagesize",
                                    label = "Countries per page",10))
    ),
    mainPanel(
      htmlOutput("myTable")
    )
  ),
  server = function(input,output){
    myOptions <- reactive({
      list(
        page=ifelse(input$pageable==TRUE,'enable','disable'),
        pageSize=input$pagesize,
        width=550
      )
    })
    output$myTable <- renderGvis({
      gvisTable(Population,options=myOptions())
    }) 
  }
)

Any help is much appreciated!

1条回答
爷、活的狠高调
2楼-- · 2020-04-10 00:39

I solved my own problem. It turns out that RStudio's native browser has difficulty displaying googleVis exhibits through Shiny. All I needed to do was open it up in Firefox... I don't think I've ever felt so much "woot" and "ugh" at the same time before.

查看更多
登录 后发表回答