Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.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
Rshiny:如何将renderUI输出传递给Selectinput中的chocies参数_R_Shiny - Fatal编程技术网

Rshiny:如何将renderUI输出传递给Selectinput中的chocies参数

Rshiny:如何将renderUI输出传递给Selectinput中的chocies参数,r,shiny,R,Shiny,我正在尝试在server.UI中输入renderUI输出,作为selectInput中choices=参数的输入。原因是,我需要使用用户选择的值作为函数的输入。当我传递这些参数时,我看到的是名称、ID、attr,而不是值。下面是我的代码。谢谢你的帮助。多谢各位 server.r列出了pubmed中的可搜索字段(例如:title、ALl fields、#UID等)。当用户选择感兴趣的字段时,用户界面需要弹出这些列表。选择需要传递给其他函数 此时,代码运行,但没有给我可搜索字段的列表,并且无法传递任

我正在尝试在server.UI中输入renderUI输出,作为selectInput中choices=参数的输入。原因是,我需要使用用户选择的值作为函数的输入。当我传递这些参数时,我看到的是名称、ID、attr,而不是值。下面是我的代码。谢谢你的帮助。多谢各位

server.r列出了pubmed中的可搜索字段(例如:title、ALl fields、#UID等)。当用户选择感兴趣的字段时,用户界面需要弹出这些列表。选择需要传递给其他函数

此时,代码运行,但没有给我可搜索字段的列表,并且无法传递任何选择

server.R

shinyServer(
function(input, output) {
output$Choose_Feild <- renderUI({
                      a = data.frame(entrez_db_searchable(db = "pubmed",
                      config = NULL))
                      unlist(a$FullName, use.names = FALSE)
                      }))

您不能以这种方式使用
renderUI

由于选项不依赖于任何输入,您可以直接传递选项:

library(shiny)

shinyUI(bootstrapPage(
    selectInput(
        inputId = "var_y", label = "Field" ,
        choices = sapply(
            rentrez::entrez_db_searchable(db = input$db, config = NULL), 
            function(x) x$FullName, USE.NAMES=FALSE
        )
    )
))
如果要动态生成选项,例如基于另一个输入,可以使用
updateSelectInput

  • 服务器.R

    shinyServer(function(input, output, session) {
        observe({
            choices <- sapply(
                rentrez::entrez_db_searchable(db = input$db, config = NULL), 
                function(x) x$FullName, USE.NAMES=FALSE
            )
            updateSelectInput(session, "var_y", choices=choices)
        })
    })
    

您是否可以发布一个可复制的示例,或者明确定义一个数据帧,比如一个被拉下的数据帧?谢谢Zero323,这非常有用
shinyServer(function(input, output, session) {
    observe({
        choices <- sapply(
            rentrez::entrez_db_searchable(db = input$db, config = NULL), 
            function(x) x$FullName, USE.NAMES=FALSE
        )
        updateSelectInput(session, "var_y", choices=choices)
    })
})
shinyUI(bootstrapPage(
    selectInput(
        inputId = "db", label="DB",
        choices=c("pmc"="pmc", "pubmed"="pubmed")
    ),
    selectInput(
        inputId = "var_y", label = "Field" ,
        choices = c()
    )
))