If you run the app below, it works fine at the beginning: you can reorder the rows of mtcars and the order appears in the verbatimTextOutput. But once you change the data to iris with the radio button, that does not work anymore.
library(shiny)
library(shinyjqui)
ui <- fluidPage(
radioButtons("radio", "Data", choices = c("mtcars", "iris")),
verbatimTextOutput("rows"),
sortableTableOutput("tbl")
)
server <- function(input, output) {
Dat <- reactive({
if(input[["radio"]] == "mtcars") {
mtcars
} else {
iris
}
})
output[["rows"]] <- renderPrint({ input[["tbl_order"]] })
output[["tbl"]] <- renderTable(Dat(), rownames = TRUE)
}
shinyApp(ui, server)
With the app below, using a renderUI reacting to the radio button, this is slightly better: this works as expected sometimes.
library(shiny)
library(shinyjqui)
ui <- fluidPage(
radioButtons("radio", "Data", choices = c("mtcars", "iris")),
verbatimTextOutput("rows"),
uiOutput("tblUI")
)
server <- function(input, output) {
Dat <- reactive({
if(input[["radio"]] == "mtcars"){
mtcars
}else{
iris
}
})
output[["rows"]] <- renderPrint({input[["tbl_order"]]})
output[["tbl"]] <- renderTable(Dat(), rownames = TRUE)
output[["tblUI"]] <- renderUI({
Dat()
sortableTableOutput("tbl")
})
}
shinyApp(ui, server)
What can we do to get an app which correctly works? Maybe an alternative to shinyjqui::sortableTabbleOutput?
