Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用actionButton对命名列表进行排序_R_List_Sorting_Shiny_Action Button - Fatal编程技术网

R 使用actionButton对命名列表进行排序

R 使用actionButton对命名列表进行排序,r,list,sorting,shiny,action-button,R,List,Sorting,Shiny,Action Button,我的名单如下: vegshop <- list( "FRUITS" = c("MANGO", "JACKFRUIT", "BANANA"), 'VEGETABLES' = c("OKRA", "BEANS", "CABBAGE") ) vegshop <- list( "FRUITS" = c("MANGO", "JACKFRUIT", "BANANA"), 'VEGETABLES' = c("OKRA", "BEANS", "CABBAGE") )

我的名单如下:

vegshop <- list(
    "FRUITS" = c("MANGO", "JACKFRUIT", "BANANA"),
    'VEGETABLES' = c("OKRA", "BEANS", "CABBAGE")
)
vegshop <- list(
    "FRUITS" = c("MANGO", "JACKFRUIT", "BANANA"),
    'VEGETABLES' = c("OKRA", "BEANS", "CABBAGE")
)
grocer <- list(
    "GROCERY" = c("CEREALS", "PULSES", "TOILETRIES"),
    "CLEANERS" = c("DETERGENTS", "FLOOR CLEANERS", "WIPES")
)

library(shiny)

ui <- shinyUI(
    fluidPage(
    actionButton(style = "font-size: 10px;",inputId = "a2z", label = "Sort-A-Z", icon = icon("sort-alpha-asc")),
    radioButtons(inputId = "shopsel", label = "SELECT SHOP", choices = c("SHOPS","SUPERMARKETS"), selected = "SHOPS", inline = TRUE),
    uiOutput("shoplist")))

server <- function(session,input, output) {
    output$shoplist <- renderUI({
        if(input$shopsel == "SHOPS") {
         selectInput(inputId = "vegShopList", label = "SHOPLIST", choices = vegshop, selected = c('MANGO', 'JACKFRUIT', 'BANANA'), multiple = TRUE, selectize = FALSE)   
        } else if(input$shopsel == "SUPERMARKETS") {
        selectInput(inputId = "smList", label = "SUPERMARKET", choices = grocer, selected = c('CEREALS', 'PULSES', 'TOILETRIES'), multiple = TRUE, selectize = FALSE)    
        }
    })

    observeEvent(input$a2z, {
        if(input$shopsel == "SHOPS") {
            updateSelectInput(session, inputId = "vegShopList", choices = vegshop[order(vegshop), decreasing = F], selected = NULL)
        } else if(input$shopsel == "SUPERMARKETS") {
            updateSelectInput(session, inputId = "smList", choices = grocer[order(grocer), decreasing = F], selected = NULL)
        }
        })
}

shinyApp(ui = ui, server = server)
但是,当我尝试使用
actionButton()
执行此操作时,出现以下错误:

the condition has `length > 1` and only the first element will be used

一个可行的例子如下:

vegshop <- list(
    "FRUITS" = c("MANGO", "JACKFRUIT", "BANANA"),
    'VEGETABLES' = c("OKRA", "BEANS", "CABBAGE")
)
vegshop <- list(
    "FRUITS" = c("MANGO", "JACKFRUIT", "BANANA"),
    'VEGETABLES' = c("OKRA", "BEANS", "CABBAGE")
)
grocer <- list(
    "GROCERY" = c("CEREALS", "PULSES", "TOILETRIES"),
    "CLEANERS" = c("DETERGENTS", "FLOOR CLEANERS", "WIPES")
)

library(shiny)

ui <- shinyUI(
    fluidPage(
    actionButton(style = "font-size: 10px;",inputId = "a2z", label = "Sort-A-Z", icon = icon("sort-alpha-asc")),
    radioButtons(inputId = "shopsel", label = "SELECT SHOP", choices = c("SHOPS","SUPERMARKETS"), selected = "SHOPS", inline = TRUE),
    uiOutput("shoplist")))

server <- function(session,input, output) {
    output$shoplist <- renderUI({
        if(input$shopsel == "SHOPS") {
         selectInput(inputId = "vegShopList", label = "SHOPLIST", choices = vegshop, selected = c('MANGO', 'JACKFRUIT', 'BANANA'), multiple = TRUE, selectize = FALSE)   
        } else if(input$shopsel == "SUPERMARKETS") {
        selectInput(inputId = "smList", label = "SUPERMARKET", choices = grocer, selected = c('CEREALS', 'PULSES', 'TOILETRIES'), multiple = TRUE, selectize = FALSE)    
        }
    })

    observeEvent(input$a2z, {
        if(input$shopsel == "SHOPS") {
            updateSelectInput(session, inputId = "vegShopList", choices = vegshop[order(vegshop), decreasing = F], selected = NULL)
        } else if(input$shopsel == "SUPERMARKETS") {
            updateSelectInput(session, inputId = "smList", choices = grocer[order(grocer), decreasing = F], selected = NULL)
        }
        })
}

shinyApp(ui = ui, server = server)
vegshop您有一个输入错误:
你在外面写:

vegshop[order(names(vegshop), decreasing = F)]
在以下范围内:

vegshop[order(vegshop), decreasing = F]
以下闪亮的代码段可能也是如此:

grocer[order(grocer), decreasing = F]