gvisTables not rendering in Shiny apps

旧巷老猫 提交于 2019-12-31 00:43:20

问题


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:


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.



来源:https://stackoverflow.com/questions/31303156/gvistables-not-rendering-in-shiny-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!