I have a shiny app which lets the user copy cells from Excel and paste in a textAreaInput in order to create a datatable out of the pasted cells. So far my code has worked with reference to this question - R Shiny: Copying cells from excel and pasting them into Shiny app and then creating a Datatable with them
ui <-fluidPage(
textAreaInput("pasted", "paste text here"),
dataTableOutput("table")
)
server <- function(input, output, session) {
df_table <- reactive({
if (input$pasted != '') {
df_table <- fread(paste(input$pasted, collapse = "\n"))
df_table <-as.data.frame(df_table)
colnames(df_table) <- c("Method")
df_table
}
})
output$table <- renderDataTable({
df_table()
}, filter="top", class = 'hover cell-border stripe', editable= TRUE,extensions= 'Buttons',
options = list(dom = 'Bfrtip',pageLength =10,
buttons = c('copy','csv','excel','pdf','print'), scrollX=TRUE),server=FALSE)
}
shinyApp(ui, server)
This works alright when I am pasting certain text and numbers into the textAreaInput. For example when I paste
- But when I am pasting certain text into the textAreaInput it is not working properly. For example when I paste
I get a wrong result as "a" is missing -
- Also, when I paste the following -
I get a wrong result -
I think this problem is because of the dashes (-) which is a special character in this case.
As a bigger picture, I think all these problems have something to do with the collapse ="\n" in paste within fread. Can someone please help me solve these problems?
EDIT
Funnily, I am not facing this issue no 2. when I am pasting two columns at the same time -