如何在R输入下拉列表中呈现不等式
我已经使用如何在R输入下拉列表中呈现不等式,r,encoding,shiny,character-encoding,R,Encoding,Shiny,Character Encoding,我已经使用shinydashboard软件包创建了一个R闪亮的应用程序。我似乎无法使用selectInput函数在下拉框中显示不等式或unicode字符。有人能帮我弄清楚如何得到大于或大于或等于的符号吗(≥) 出现在下拉列表中?以下是一个示例,演示了该问题: library(shiny) library(shinydashboard) library(shinyjs) ui <- shinyUI(dashboardPage( dashboardHeader(), dashboar
shinydashboard
软件包创建了一个R闪亮的应用程序。我似乎无法使用selectInput
函数在下拉框中显示不等式或unicode字符。有人能帮我弄清楚如何得到大于或大于或等于的符号吗(≥) 出现在下拉列表中?以下是一个示例,演示了该问题:
library(shiny)
library(shinydashboard)
library(shinyjs)
ui <- shinyUI(dashboardPage(
dashboardHeader(),
dashboardSidebar(collapsed = FALSE,
selectInput("Age", "4. Select Age Group:",
c("\u2265 6 months" = "_6plus",
"&ge 6 months" = "_6plus2",
"≥ 6months" = "_6plus3",
"≥ 6months" = "_6plus3",
"6 months - 4 years" = "_6_4"))),
dashboardBody(
useShinyjs()
)
))
server <- shinyServer(function(input, output, session) {
#addClass(selector = "body", class = "sidebar-collapse")
})
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinydashboard)
图书馆(shinyjs)
ui在研究这个问题一段时间后,我找到了一个解决方案,但我仍然希望得到其他人的建议。我能够做到这一点的唯一方法是将年龄类别放在UTF-8文本文件中,比如agegroups.txt
,用readr
包读取文件,从读入tibble,然后使用向量创建下拉列表。下面是一个有效的示例:
文本文件:
≥6 months
6 months - 17 years
≥18 years
library(readr)
agegroups <- unique(read_csv("d:\\\\agegroups.txt"))
agegroupchoices <- setNames(agegroups$AgeGroups, agegroups$AgeGroups)
ui <- shinyUI(dashboardPage(
dashboardHeader(),
dashboardSidebar(
collapsed = FALSE,
selectInput("Age", "4. Select Age Group:", agegroupchoices)
),
dashboardBody(
useShinyjs()
)
))
server <- shinyServer(function(input, output, session) {})
shinyApp(ui = ui, server = server)
R代码:
≥6 months
6 months - 17 years
≥18 years
library(readr)
agegroups <- unique(read_csv("d:\\\\agegroups.txt"))
agegroupchoices <- setNames(agegroups$AgeGroups, agegroups$AgeGroups)
ui <- shinyUI(dashboardPage(
dashboardHeader(),
dashboardSidebar(
collapsed = FALSE,
selectInput("Age", "4. Select Age Group:", agegroupchoices)
),
dashboardBody(
useShinyjs()
)
))
server <- shinyServer(function(input, output, session) {})
shinyApp(ui = ui, server = server)
库(readr)
年龄组您可以使用selectizeInput
的render
选项在选项名称中使用HTML代码:
library(shiny)
render <- "
{
option: function(data, escape){return '<div class=\"option\">'+data.label+'</div>';},
item: function(data, escape){return '<div class=\"item\">'+data.label+'</div>';}
}"
ui <- fluidPage(
selectizeInput(
"age", "Age category",
choices = c(
"≤ 6 months" = 1,
"6 months - 17 years" = 2,
"≥ 18 years" = 3
),
options = list(
render = I(render)
)
)
)
server <- function(input, output){}
shinyApp(ui, server)
库(闪亮)
提供