numeric vector input?

727 views
Skip to first unread message

qians...@hotmail.com

unread,
Nov 23, 2013, 12:52:40 PM11/23/13
to shiny-...@googlegroups.com
Hey guys,

I am trying to use a numeric vector as my input, it seems numericInput is unable to handle vectors, so anyone knows how to do this? Thank you and have a nice weekend!

Best,

Su

Stéphane Laurent

unread,
Nov 24, 2013, 3:18:25 AM11/24/13
to shiny-...@googlegroups.com
Hi,
Two solutions : 

 1) Use matrixInput() from the shinyIncubator package
 2) Use textInnput() and convert the text to a vector in server.R

Stéphane Laurent

unread,
Nov 24, 2013, 4:32:39 AM11/24/13
to shiny-...@googlegroups.com, qians...@hotmail.com
Hi Su,

Please send your reply to the Shiny group.

- If you really want to enter raw R syntax in textInput(), use this:
> x <- "c(2,3)"
> eval(parse(text=x))
[1] 2 3

- I have another solution but it is on my other computer, please wait a minute


Hey Stephane,
Thanks for your help on this. I will try the shinyIncubator package solution later. I actually tried the second solution of yours yesterday, I put down sth like c(5,2) (or simply (5,2)), but the program recognize it as a character 'c(5,2)', so when I apply as.numeric() to it, it does not work out.
Su

Stéphane Laurent

unread,
Nov 24, 2013, 4:37:41 AM11/24/13
to shiny-...@googlegroups.com, qians...@hotmail.com
Another way using textInput():

Use the following function:
  unlist(regmatches(string,gregexpr("[[:digit:]]+\\.*[[:digit:]]*",string)), use.names=FALSE)
Then :
> x <- "0 1 2"
> y <- "0, 1, 2"
> as.numeric(numextractall(x))
[1] 0 1 2
> as.numeric(numextractall(y))
[1] 0 1 2

qians...@hotmail.com

unread,
Nov 24, 2013, 10:42:31 AM11/24/13
to shiny-...@googlegroups.com, qians...@hotmail.com
Thank you Stephane, I really appreciate your help. Have wonderful day !

Su
Reply all
Reply to author
Forward
0 new messages