R SHINY:将单元格从Excel复制到SelecizeInput [英] R shiny: Copying Cells from Excel into SelectizeInput

查看:20
本文介绍了R SHINY:将单元格从Excel复制到SelecizeInput的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我们需要的内容(Excel中的每一行都是其在文本字段中的条目)

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

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


编辑%1

异常:

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

仅显示一个字符串,但需要4个"母"标签(如果可能)

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

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

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


编辑%2

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

推荐答案

这里有一个适用于我的最小示例。

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, "
"))
    )

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

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

shinyApp(ui, server)

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

这篇关于R SHINY:将单元格从Excel复制到SelecizeInput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆