pickerInput显示数值而不是字符

问题描述 投票:0回答:1

这是我的虚拟dataframe和变量社交,其中包含在pickerInputglobal.R中填充的独特文本

social_media <- c("Facebook","Instagram","YouTube","Snapchat","Twitter")
founder <- c("PersonA","PersonB","PersonC","personD","personE")
hits <- c(23,56,76,33,12)

DF <- data.frame(social_media, founder, hits)
social <- unique(DF$social_media)

app.R,我实施了pickerInput如下:

library(shinyWidgets)
library(shiny)

ui <- fluidPage(  
  titlePanel("pickerInput"),
  sidebarLayout(
    sidebarPanel(
      pickerInput("social","social media", choices = social, multiple = FALSE, options = list(deselectAllText = TRUE,actionsBox=TRUE))
    )
    ,
    mainPanel() 
    ))

server <- function(input, output) {}
shinyApp(ui, server)

当我运行应用程序时,列表仅显示值而不显示文本。当选择出现时,我可能会丢失或不这样做?

enter image description here

r shiny
1个回答
1
投票

你的变量social是类型因子。这就是pickerInput()显示数字输出的原因。

如果你避免创建因素:

DF <- data.frame(social_media, founder, hits, stringsAsFactors = FALSE)

它会将选项显示为字符。

© www.soinside.com 2019 - 2024. All rights reserved.