gpt4 book ai didi

r - 如何从pickerInput文本换行选择,如果选择的长度很长,选择通常会在屏幕之外结束

转载 作者:行者123 更新时间:2023-12-04 10:52:13 24 4
gpt4 key购买 nike

pickerInput 中的选项总是在单行中。有没有办法将它们带到下一行? This is a problem when the length of the choice is very long making the choice go out of the screen.我特别需要pickerInput,因为它具有实时搜索,全选/取消选择其中的所有功能。

library("shiny")
library("shinyWidgets")
ui <- fluidPage(
pickerInput(inputId="id",label="Some name",
choices=c("Choice 1 is small","Choice 2 is average sized",
"But choice 3 is very big and sometimes when the length of the qption is long it leaves the screen, so I need a UI fix to wrap the question to fit the width of the pickerInput. I want pickerInput because it has select all/deselect all button."),
selected=NULL,multiple=T,options=list(`actions-box`=TRUE,size=10,`selected-text-format`="count > 3")
)
)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)

最佳答案

这里有两个解决方案,都使用 choicesOpt参数以防止修改服务器端的值。

1. 截断你的字符串以固定宽度

我用过 stringr::str_trunc :

library("shiny")
library("shinyWidgets")

my_choices <- c(
"Choice 1 is small","Choice 2 is average sized",
"But choice 3 is very big and sometimes when the length of the qption is long it leaves the screen, so I need a UI fix to wrap the question to fit the width of the pickerInput. I want pickerInput because it has select all/deselect all button."
)

ui <- fluidPage(

pickerInput(
inputId = "id",
label = "Some name",
choices = my_choices,
selected = NULL,
multiple = TRUE,
options = list(
`actions-box` = TRUE, size = 10, `selected-text-format` = "count > 3"
),
choicesOpt = list(
content = stringr::str_trunc(my_choices, width = 75)
)
),
verbatimTextOutput(outputId = "res")
)

server <- function(input, output, session) {
output$res <- renderPrint(input$id)
}

shinyApp(ui = ui, server = server)

enter image description here

2. 插入断线

我用过 stringr::str_wrap将文本段落分成几行,然后 stringr::str_replace_all替换 \n<br> (HTML 版本 \n)
library("shiny")
library("shinyWidgets")

my_choices <- c(
"Choice 1 is small","Choice 2 is average sized",
"But choice 3 is very big and sometimes when the length of the qption is long it leaves the screen, so I need a UI fix to wrap the question to fit the width of the pickerInput. I want pickerInput because it has select all/deselect all button."
)
my_choices2 <- stringr::str_wrap(my_choices, width = 80)
my_choices2 <- stringr::str_replace_all(my_choices2, "\\n", "<br>")

ui <- fluidPage(

# tags$style(".text {width: 200px !important; word-break: break-all; word-wrap: break-word;}"),
pickerInput(
inputId = "id",
label = "Some name",
choices = my_choices,
selected = NULL,
multiple = TRUE,
options = list(
`actions-box` = TRUE, size = 10, `selected-text-format` = "count > 3"
),
choicesOpt = list(
content = my_choices2
)
),
verbatimTextOutput(outputId = "res")
)

server <- function(input, output, session) {
output$res <- renderPrint(input$id)
}

shinyApp(ui = ui, server = server)

enter image description here

关于r - 如何从pickerInput文本换行选择,如果选择的长度很长,选择通常会在屏幕之外结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51355878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com