【发布时间】:2014-10-10 01:13:34
【问题描述】:
我正在尝试创建一个闪亮的应用程序,它基本上是一个表格,带有一个关于选项卡。
我遇到了两件事:
其中一列是美元金额。我希望格式为 1,225 美元。我能做到的最接近的方法是使用 paste0,但是当您对列进行排序时,它不能按预期工作,而且我没有得到数千个逗号。
我希望能够使用“全部、A、C、D”选项的下拉菜单。如果我选择“A”,它将只显示“Something==A”的表格。现在这正在工作,但我不确定我是否以最好的方式编码。
这是我的 ui.R
library(shiny)
shinyUI(fluidPage(
title = 'Some tittle',
sidebarLayout(
sidebarPanel(
checkboxGroupInput('show_vars', 'Columns to show:',
c("Something", "Money"),
selected = c("Money")),
selectInput(inputId = "Something",
label = "Choose a category",
choices = c("All", "A", "C", "D"),
selected = "All")
),
mainPanel(
tabsetPanel(
id = 'dataset',
tabPanel('Table', dataTableOutput('mytable1')),
tabPanel('about', includeMarkdown("about.md"))
)
)
)
))
我的服务器.R
library(shiny)
library(dplyr)
DF1 = data.frame("Rank"=1:4, "Something"=as.factor(c("A","A","C","D")), "Money"=c(2345.5, 1234.67, 5.2, 9878.46))
# change the data to have dollar sign
DF1 = DF1 %>% mutate(Money= paste0("$",round(Money,0)))
original = DF1
shinyServer(function(input, output) {
observe({
if(input$Something!="All"){
DF1 = original %>% filter(Something==input$Something)
# a large table, reative to input$show_vars
output$mytable1 <- renderDataTable({
DF1[, c("Rank", input$show_vars), drop = FALSE]
})
}else{
DF1 = original
output$mytable1 <- renderDataTable({
DF1[, c("Rank", input$show_vars), drop = FALSE]
})
}
})
})
还有我的 about.md
# Title
+ bla
+ bla
+ bla
感谢您的帮助!
【问题讨论】:
-
美元格式见
scales::dollar()。
标签: shiny