[英]Possible to only show first and last X rows in R Shiny
是否有可能使用發亮的renderdatatable僅顯示第一行和最后一行? 如果訂購表,則更改該表。
對於這個例子
if (interactive()) {
shinyApp(
ui = fluidPage(
fluidRow(
column(12,
dataTableOutput('table')
)
)
),
server = function(input, output) {
output$table <- renderDataTable(data.frame(A = 1:20, B = 20:1),
options = list(
pageLength = 10
)
)
}
)
}
所需的輸出將是
A B
1 1 20
20 20 1
並且如果用戶改為按B訂購
A B
1 20 1
20 1 20
您可以在反應空間中操作數據表以創建所需的任何行為。 在這里,我對df對象的頭部和尾部進行了排序/重新排序:
if (interactive()) {
library(shiny)
shinyApp(
ui = fluidPage(
fluidRow(
column(3,
selectInput("ordering", "How to order", choices = c("A", "B"), selected = "A")),
column(9,
dataTableOutput('table')
)
)
),
server = function(input, output) {
output$table <- renderDataTable({
df <- data.frame(A = 1:20, B = 20:1)
df <- df[order(df[[input$ordering]]), ]
df_new <- rbind(head(df,1), tail(df,1))
df_new
},
options = list(pageLength = 10))
}
)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.