【问题标题】:pickerInput showing numeric values instead of characterspickerInput 显示数值而不是字符
【发布时间】:2018-11-11 20:31:59
【问题描述】:

这是我的虚拟 dataframe 和变量 social,它承载要在 pickerInput 中填充的唯一文本 global.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)

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

【问题讨论】:

  • 试试这行代码social &lt;- as.character(unique(DF$social_media))
  • 下面的答案对你有用吗? @Sayari?

标签: r shiny


【解决方案1】:

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

如果你避免创建因子:

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

它将选择显示为字符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多