![](/img/trans.png)
[英]How to use a reactive list with reactive dataframe and R Highcharter in Shiny App
[英]R Shiny App - how to sort elements of this reactive list
我正在尝试对通过Shinyapp添加的csv文件的元素进行排序。
我无法理解如何按代码中的第一列对项目进行排序。 这是我尝试对列表进行排序的代码片段。 原始完整代码/问题位于此处
server <- function(input, output) {
filedata <- reactive({
infile <- input$datafile
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
read.csv(infile$datapath)
})
# my attempt to sort
filedata() <- filedata()[ order(filedata()[[input$selectcol1]]) ]
x <- reactive({
1:dim(filedata())[1]
})
output$selectcol1 <- renderUI({
df <-filedata()
if (is.null(df)) return(NULL)
items=names(df)
names(items)=items
selectInput("selectcol1", "Best Estimate",items)
})
我用这一步解决了
server <- function(input, output) {
filedata <- reactive({
infile <- input$datafile
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
temp<-read.csv(infile$datapath)
#return
temp[order(temp[, 1]),]
})
并删除
# my attempt to sort
filedata() <- filedata()[ order(filedata()[[input$selectcol1]]) ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.