gpt4 book ai didi

R Shiny : Copying Cells from Excel into SelectizeInput

转载 作者:行者123 更新时间:2023-12-04 02:40:12 36 4
gpt4 key购买 nike

我希望能够从 Excel 复制文本行并将其粘贴到我们应用程序的文本字段中,如下所示:

突出显示所有单元格并复制到示例标签文本字段中:

Excel

我们想要的(Excel 中的每一行在文本字段中都有自己的条目)

Separated Data

当我们粘贴 Excel 中的行(Excel 中的每一行合并为一个条目)时,应用程序当前执行的操作:

Combined Data

有没有办法将单元格复制到类似 SelectizeInput 的文本字段中,并以某种方式分隔从 Excel 复制的每个单元格?谢谢。


编辑 1

异常(exception):

1) 当行具有相同的值时:

enter image description here

只有一个字符串显示,但需要的是 4 个“女性”标签(如果可能)

enter image description here

2) 单元格的值带有空格:

enter image description here

每个标签之间用空格隔开,像DAY这样的重复词只显示一次:

enter image description here

理想情况下,这是需要的:

enter image description here


编辑 2

当分隔符设置为/n 时,所有内容都合并到一个标签中,而不是单独的标签

enter image description here

最佳答案

这是一个适合我的最小示例。

library(shiny)

ui <- fluidPage(
selectizeInput(
"foo",
label = "inputs",
choices = "",
multiple = T,
options = list(delimiter = " ", create = T)
),
textOutput("results")
)

server <- function(input, output, session) {
output$results <- renderText(
paste(paste("item", input$foo), collapse = " || ")
)
}

shinyApp(ui, server)

如果您删除 delimiter = "" 选项,行为将恢复为不需要的默认值。从 Excel 复制时,项目与空格连接,其中 selectize.js 需要逗号。

https://shiny.rstudio.com/articles/selectize.html

https://github.com/selectize/selectize.js/blob/master/docs/usage.md


为什么我认为这是错误的做法:

library(shiny)

ui <- fluidPage(
selectizeInput(
"foo",
label = "inputs",
choices = "",
multiple = T,
options = list(
delimiter = " ",
create = T
)
),
textOutput("results"),

hr(),

"textInput",
textInput("pasted1", "paste text here"),

h5("Raw hex code points (20 is space, 0a is linefeed"),
textOutput("verb1"),
h5("Vector of results from splitting on '\\n'"),
textOutput("split1"),

hr(),

"textAreaInput",
textAreaInput("pasted2", "paste text here"),

h5("Raw hex code points (20 is space, 0a is linefeed"),
textOutput("verb2"),
h5("Vector of results from splitting on '\\n'"),
textOutput("split2")
)

server <- function(input, output, session) {
output$results <- renderText(
paste(paste("item", input$foo))
)

output$verb1 <- renderPrint(charToRaw(input$pasted1))

output$split1 <- renderText(
paste(strsplit(input$pasted1, "\n"))
)

output$verb2 <- renderPrint(charToRaw(input$pasted2))

output$split2 <- renderText(
paste(strsplit(input$pasted2, "\n"))
)
}

shinyApp(ui, server)

我认为 selectizeInputtextInput 一样,将所有空格(包括换行符)清理为单个空格。如果您使用 textAreaInput 作为您的容器,它将逐字复制粘贴的文本,您可以自己在换行符上进行拆分,然后在您要使用 返回的选项的任何地方使用该向量选择输入

enter image description here

关于R Shiny : Copying Cells from Excel into SelectizeInput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59773066/

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