【问题标题】:change selectizeInput choices - wrong values in menu更改 selectizeInput 选项 - 菜单中的错误值
【发布时间】:2015-10-20 00:08:21
【问题描述】:

我尝试制作这样的选择菜单:

Interactively change the selectInput choices

除了一件事之外,一切都很好: 虽然我没有做任何不同的事情(见下面的图片链接),但我得到了索引,而不是获取值(如麦当劳)。我的错误在哪里?

Picture

这里是我的 global.R:

partners<- read.csv("genes.csv", header=TRUE, fill=TRUE)

服务器.R

shinyServer(function(input, output) {

#subTable
searchResult<- reactive({
subset(partners, grepl(input$nameSearch, partners$name))
})

output$searchResults <- renderTable({ 
searchResult()[,1]
})


output$selectUI <- renderUI({ 
selectizeInput("partnerName", "Click in and select", choices=searchResult()[,1], multiple=TRUE )
})
})

ui.R

library(shiny)

shinyUI(pageWithSidebar(
# Give the page a title
titlePanel("Tilte"),

sidebarPanel(

textInput("nameSearch", "Search for name", "Blah"),
htmlOutput("selectUI"),
br(),
submitButton("Update View"),
br()

),
# Create a spot for the barplot
mainPanel(
textOutput("text"),
plotOutput("plot")  
)
)
)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    我认为你得到的不是索引,而是一个因子的整数表示。检查partners[,1] 的类。试试

    output$selectUI <- renderUI({ 
        selectizeInput("partnerName", "Click in and select",
                       choices=as.character(searchResult()[,1]), multiple=TRUE )
    })
    

    您也可以在读取数据时添加stringsAsFactors=FALSE 选项。

    【讨论】:

    • 非常感谢,这就是问题所在并解决了问题!我是 R 新手,对这个因素——“问题”不太熟悉。我真的很高兴你给了我小费!
    • 没问题,因素一开始很混乱,为了节省空间,它们被存储为整数,并且每个整数都有一个标签。
    猜你喜欢
    • 2023-03-28
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 2017-06-10
    相关资源
    最近更新 更多