R Shiny RenderDataTable显示选项

时间:2014-08-04 19:29:44

标签: javascript r shiny shiny-server

Shiny Output]

所以我有这张表,我使用ShinyDash包制作。鉴于记录数量很少,我想删除页码,只显示上一页/下一页。我还要删除左上方的框以选择每页的记录数,并将其默认设置为5.

这是我目前的代码,虽然最后一行选项应该真的很重要:

output$values <- renderDataTable({ 
}
 df <- data.frame(
Period = c("SP15", "FA14", "SU14", "SP14", "FA13", "SP13"),
StartedApps = c(full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SP15"],
    full$Cum[full$Day == as.numeric(elapsed) & full$Group == "FA14"],
    full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SU14"],
    full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SP14"],
    full$Cum[full$Day == as.numeric(elapsed) & full$Group == "FA13"],
    full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SP13"]),
Pct = c("", 
percent(full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SP15"]/full$Cum[full$Day == as.numeric(elapsed) & full$Group == "FA14"] - 1),
percent(full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SP15"]/full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SU14"] - 1),
percent(full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SP15"]/full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SP14"] - 1),
percent(full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SP15"]/full$Cum[full$Day == as.numeric(elapsed) & full$Group == "FA13"] - 1),
percent(full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SP15"]/full$Cum[full$Day == as.numeric(elapsed) & full$Group == "SP13"] - 1)),
CompletedApps = c(fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "SP15"],
    fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "FA14"],
    fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "SU14"],
    fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "SP14"],
    fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "FA13"],
    fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "SP13"]),
Pct2 = c("", 
percent(fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "SP15"]/fullcomp$Cum[fullcomp$Day == as.numeric(elapsed)  & fullcomp$Group == "FA14"] - 1),
percent(fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "SP15"]/fullcomp$Cum[fullcomp$Day == as.numeric(elapsed)  & fullcomp$Group == "SU14"] - 1),
percent(fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "SP15"]/fullcomp$Cum[fullcomp$Day == as.numeric(elapsed)  & fullcomp$Group == "SP14"] - 1),
percent(fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "SP15"]/fullcomp$Cum[fullcomp$Day == as.numeric(elapsed)  & fullcomp$Group == "FA13"] - 1),
percent(fullcomp$Cum[fullcomp$Day == as.numeric(elapsed) & fullcomp$Group == "SP15"]/fullcomp$Cum[fullcomp$Day == as.numeric(elapsed)  & fullcomp$Group == "SP13"] - 1)))

df$Pct <- recode(df$Pct, "'Inf%' = 'NA'")
df$Pct2 <- recode(df$Pct2, "'Inf%' = 'NA'")
df$StartedApps <- as.integer(df$StartedApps)
df$CompletedApps <- as.integer(df$CompletedApps)
names(df) <- c("Period", "Starts", "Pct Change", "Submits", "Pct Change")
df
}, options = list(pagingType = "simple", bFilter = FALSE, aLengthMenu = 5, iDisplayLength = 5)) 

该应用程序构建在DataTables JavaScript库(http://datatables.net/reference/option/)之上,但我还不清楚JavaScript是否足以解决这个问题:(任何想法?

2 个答案:

答案 0 :(得分:1)

您可以使用sPaginationType选项。在data.table(1.10)的后一版本中,pagingType http://datatables.net/reference/option/pagingType具有更大的灵活性:

library(shiny)
runApp(list(
  server = function(input, output, session) {
  output$dt <- renderDataTable({
    data = data.frame(setNames(replicate(15, rnorm(100), simplify = FALSE), letters[1:15]))
    return(data)
  },
  options = 
    list(sPaginationType = "two_button")
  )
}
, ui = navbarPage("Foo", id="page", collapsable=TRUE, inverse=FALSE,
                   tabPanel("Bar",
                            dataTableOutput("dt")
                   )
)
)
)

答案 1 :(得分:1)

更新,以防有人正在查看:

library(shiny)
runApp(list(
  ui = fluidPage(
    DT::dataTableOutput("dt")
  )
  ,
  server = function(input, output, session) {
    data = data.frame(setNames(replicate(15, rnorm(100), simplify = FALSE), letters[1:15]))

    output$dt <- DT::renderDataTable({
      DT::datatable(data,
                    options = 
                      list(pagingType = "simple")  
      )
    }
    )
  }
)
)