我想按兩列排序數據幀,第一個數字是因子和第二個數字,但是這是選擇閃亮的。當用戶選擇一個數據框時,將數據框排序爲兩列
當我在指定的列上使用這條線時,效果很好。
iris1<-iris[with(iris,order(Species,Sepal.Length,decreasing = T)), ]
但是裏面閃閃發亮,我將Sepal.Length替換爲無效值並返回錯誤。請參閱MRE
# ui.R
library(shiny)
shinyUI(pageWithSidebar(
# Application title
headerPanel("Miles Per Gallon"),
sidebarPanel(selectInput("a","select column",c("Sepal.Length","Sepal.Width"))),
mainPanel(tableOutput("b"))
))
# server.R
library(shiny)
shinyServer(function(input, output) {
col<-reactive({input$a})
output$b<- renderTable({
########### this line probably causes the problem
iris1<-iris[with(iris,order(Species,col(),decreasing = T)), ]
})
})
錯誤我得到的是
Error in order(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, :
argument lengths differ
哪一列山坳()是指在沒有山坳由用戶選擇? –
Sepal.Length在那裏作爲默認 –