I want to be able to copy rows of text from Excel and paste it into the text field in our app like this:
Highlight all cells and copy into the Sample labels text field:
What we want (each row from Excel is its own entry in the text field)
What the app currently does when we paste the rows from Excel (each row from Excel combines into one entry):
Is there a way to copy cells into a SelectizeInput-like text field and somehow separate each cell whwen copied from Excel? Thank you.
Edit 1
Exceptions:
1) When rows have the same values:
only one string shows but what is needed is 4 "Female" labels (if possible)
2) Cells have values with a space:
each label is separated by a space, and repeat words like DAY are only shown once:
Ideally this is what is needed:
Edit 2
When delimiter is set to /n, everything is combined into one label instead rather than separate labels
Here is a minimal example that works for me.
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)
If you take out the delimiter = " "
option, the behavior reverts to the undesired default. When copying from Excel, items are concatenating with spaces, where selectize.js
is expecting commas.
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)
I think that selectizeInput
, like textInput
, sanitizes all whitespace, including newlines, to be single spaces. If you use textAreaInput
as your container, it will copy the pasted text verbatim, and you can do the splitting on newlines yourself, then use that vector wherever you were going to use the choices returned by selectizeInput
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With