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