【问题标题】:Shiny R: Populate a list from input and return list on output via reactiveShiny R:通过响应式从输入填充列表并在输出上返回列表
【发布时间】:2015-06-10 13:11:25
【问题描述】:

我尝试使用从闪亮输入传递的列表元素填充闪亮列表。该列表应累积所有做出的选择。该列表最终应该被发送到闪亮的输出。实际上我已经得到了一个可以发送到输出的列表。然而,这个列表的长度总是只有 1,并且这个单个元素会随着输入而更新。实际上我只对列表的“名称”感兴趣,这就是为什么我将值 1 分配给每个名称元素:

用户界面
shinyUI(
    fluidRow(   
        column(1,
            # reactive input 
            selectInput("Input1", 
                        label = "Select Parameter 1",
                        choices = c("none",letters[1:16]),
                        multiple = T),
            selectInput("Input2", 
                        label = "Select Parameter 2",        
                        choices = c("none",c(1:24) )
                        multiple = T),        
            # printout of list
            htmlOutput("printoutList")
        ) # end of column
    ) # end of fluid row
) # end of Shiny UI

闪亮的.R

# create an empty list
container <- list()
shinyServer(function(input, output) {

    # pass over input to reactive
    inputInfo <- reactive({
        if(input$Input1 == "none" | input$Input2 == "none") {
            "-"               
        } else { 
            paste(input$Input1 ,input$Input2, sep = "")
        }
    }) 

    # fill list and pass over list to output 
    output$printoutList <- renderUI({                    
        container[[inputInfo()]] <- 1
        paste("You have chosen: ", names(container), sep = "")        
    }) 

)} #end of shinyServer function 

知道如何解决这个问题吗?我已经尝试了很多......不幸的是我对 R 很陌生,尤其是闪亮的!我真的很感激任何帮助!谢谢!

【问题讨论】:

    标签: r list shiny


    【解决方案1】:

    为 selectInput 包含 multiple = TRUE 参数

     selectInput("Input1", 
    
              label = "Select Parameter 1",
              choices = c("none",letters[1:16]),
              multiple = TRUE
    
              )
    

    但您的服务器和 ui 文件似乎混淆了,您的代码中没有 shinyServer 功能。

    【讨论】:

    • 感谢詹姆斯的回答!你是对的,我的脚本中有一些复制粘贴错误,对此感到抱歉。不幸的是,我仍然收到您的编辑错误消息:运行中的警告(timeoutMs):
    • 较长的对象长度不是较短对象长度的倍数 run(timeoutMs) 中的警告:条件的长度 > 1 并且只会使用第一个元素 [[&lt;-(*tmp*, flaggedWell(), value = c("b3", "e5", "g8")) : no such index at level 1 警告在 run(timeoutMs) : 条件长度 > 1 并且只使用第一个元素
    • 首先我会将 selected = "none" 参数添加到 selectInput 函数中,这样它就不会返回 NULL 。您还可以使用 validate 函数来确保您传递了适当的输入。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    • 2020-06-07
    • 2017-09-13
    • 2018-06-16
    • 2020-08-15
    • 2014-04-21
    相关资源
    最近更新 更多