This app demonstrates how to dynamically update a
rank_list()
And the full code:
## Example shiny app that dynamically updates a rank list
library(shiny)
library(sortable)
<- fluidPage(
ui fluidRow(
column(
width = 4,
selectInput("data", label = "Select the data source", choices = c("mtcars", "iris")),
selectInput("nrow", label = "Number of rows", choices = c("15", "50", "All")),
uiOutput("sortable")
),column(
width = 8,
h2("Results"),
tableOutput("table")
)
)
)
<- function(input, output, session) {
server <- reactiveValues(data = data.frame())
rv
observeEvent(input$data, {
$data <- get(input$data)
rv
})
observeEvent(input$sortable, {
$data <- rv$data[input$sortable]
rv
})
$sortable <- renderUI({
outputrank_list("Drag column names to change order", names(rv$data), "sortable")
})
$table <- renderTable({
outputif (input$nrow == "All") {
$data
rvelse {
} head(rv$data, as.numeric(input$nrow))
}
})
}
shinyApp(ui, server)