交互式更改selectInput选择 [英] Interactively change the selectInput choices
问题描述
最初,我创建了一个闪亮的界面,它带有一个参数"company id"和"date",但是在这里我们遇到了一个问题:大多数人不知道我们与之合作的公司仅凭其名称即ID(麦当劳(McDonalds) , 窝棚电台).
Originally I create this shiny interface that takes in a parameter "company id" and "date", but here we have a problem: most people dont know the companies we work with by their id, only their name, i.e. (McDonalds, Radioshack).
所以我想理想地创建这样的搜索功能
So I want to ideally create a search function like this
我目前的想法是将包含所有合作伙伴公司及其ID的列表传递给global.R.然后将textInput作为搜索变量传递,并在服务器端执行搜索.但是,我迷路于如何将searchResults传递回selectInput面板上的UI?
My current idea is to pass in a table including a list of all our partner companies and their ids to global.R. Then pass in the textInput as the search variables and perform the search on server side. However, I get lost on how to pass searchResults back into the UI on a selectInput panel?
我当前的代码:
ui.R
library(shiny)
shinyUI(pageWithSidebar(
sidebarPanel(
textInput("nameSearch", "Or, Search for company name", 'McDonald'),
selectInput("partnerName", "Select your choice", list( "searchResults" ),
br(),
submitButton("Update View"),
br(),
),
server.R
shinyServer(function(input, output) {
#subTable
searchResult<- reactive({
subset(partners, grepl(input$nameSearch, partners$name))
})
output$searchResults <- renderTable({
searchResult[,1]
})
global.R
partners<- read.csv("partnersList.csv", fill=TRUE)
partnersList就是这种格式
partnersList is just in this format
name id
------------------
McDonalds 1
Wendy's 2
Bestbuy 3
推荐答案
您需要使UI具有反应性.我还没有测试(也缺少数据),但我认为应该可以工作.在server.R
中添加:
You need to make the UI reactive. I haven't tested this (miss data for it too) but should work I think. In server.R
add:
output$selectUI <- renderUI({
selectInput("partnerName", "Select your choice", searchResult()[,1] ),
})
在ui.R
中,将selectInput替换为:
And in ui.R
replace the selectInput with:
htmlOutput("selectUI")
这篇关于交互式更改selectInput选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!