R 闪亮:将单元格从 Excel 复制到 SelectizeInput

kar*_*uno 3 r shiny

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

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

电子表格

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

分离数据

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

组合数据

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


编辑 1

例外:

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

在此处输入图片说明

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

在此处输入图片说明

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

在此处输入图片说明

每个标签由一个空格分隔,像DAY这样的重复词只显示一次:

在此处输入图片说明

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

在此处输入图片说明


编辑 2

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

在此处输入图片说明

Bri*_*ian 5

这是一个对我有用的最小示例。

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)
Run Code Online (Sandbox Code Playgroud)

如果您取消该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)
Run Code Online (Sandbox Code Playgroud)

我认为selectizeInput,像 一样textInput,将所有空格(包括换行符)清理为单个空格。如果您textAreaInput用作容器,它将逐字复制粘贴的文本,您可以自己在换行符上进行拆分,然后在要使用selectizeInput.

在此处输入图片说明