问题描述
我正在尝试解决的实际问题:我正在创建一个包含数据表的仪表板。我想要使用逗号格式化数字作为数千个分隔符,但是当(与明亮)一起使用DT包时,显然有一个问题,因为使用逗号分隔的格式会使DT :: renderDataTable以字符形式读取数字,它影响数字的排序。 (DT的数字格式化功能不适用于Shiny,它会出现。)
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.)
我到目前为止:唯一的解决方案,已经能够找到的是使用googleVis而不是DT创建表。现在我正在遇到一个不同的问题(如下所述),但是我真正关心的是使用逗号分隔的数字的数据表与数字排序。
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.
GoogleVis问题:当我在Shiny应用程序之外使用gvisTable时,它们呈现非常好,但在Shiny中使用renderGvis和htmlOutput时,它们根本不渲染。例如,我将借用
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.
不使用Shiny,我的代码如下所示:
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)
使用Shiny,就像这样:
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())
})
}
)
任何帮助都非常感激!
推荐答案
我解决了自己的问题。事实证明,RStudio的本机浏览器很难通过Shiny显示googleVis的展览。所有我需要做的是在Firefox中打开它...我不认为我以前曾经感觉到过这么多的愚蠢和ugh。
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.
这篇关于gvisTables不会在Shiny应用程序中渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!