user90
user90

Reputation: 381

How to add space on selectInput list

I was trying to list using selectInput from a file as like this

data4<-read.delim("data/data4.txt",sep = ",",header = T)

selectInput("show_vars5", 'YYYYY', names(data4), multiple=TRUE, selectize=TRUE,selected = 'xxx')

But list is showing with dot instead of space. Example if I have "cat dog" in data4, the selectInput showing as like this "cat.dog" How to change it ?

Upvotes: 0

Views: 39

Answers (1)

Ben373
Ben373

Reputation: 971

You have column names with spaces in them.

read.delim is automatically converting them by concatenating them with a dot.

Exchanging names(data4) with gsub('\\.', ' ', names(data4)) should do the trick. This replaces every occurrence of a dot with a space in the names of data4.

edit: As @Stéphane Laurent pointed out, using read.delim with check.names = FALSE as argument will prevent the conversion of the names in the first place.

Upvotes: 1

Related Questions