Autocomplete as a Shiny input?

4,273 views
Skip to first unread message

John Reeder

unread,
Jan 16, 2013, 8:26:23 PM1/16/13
to shiny-...@googlegroups.com
Just curious if anyone has done anything with autocomplete as a Shiny input, instead of the pull down menu/selectInput option.  I was looking at the Chosen js plugin and trying to figure out if that might be worth trying as an input option.

Joe Cheng

unread,
Jan 16, 2013, 10:52:49 PM1/16/13
to shiny-...@googlegroups.com
See also http://ivaynberg.github.com/select2/, I think these would be very worthwhile to turn into Shiny components.


On Wed, Jan 16, 2013 at 5:26 PM, John Reeder <jreed...@gmail.com> wrote:
Just curious if anyone has done anything with autocomplete as a Shiny input, instead of the pull down menu/selectInput option.  I was looking at the Chosen js plugin and trying to figure out if that might be worth trying as an input option.

--
 
 

John Reeder

unread,
Jan 17, 2013, 1:36:00 AM1/17/13
to shiny-...@googlegroups.com

That looks great.  I'll take a closer look. Thx.

--
 
 

Vincent

unread,
Jan 17, 2013, 5:41:06 AM1/17/13
to shiny-...@googlegroups.com, ree...@svn.com
I was able to get select2 working. Very nice although the font is smaller than I would like. Haven't figured out how to change that yet. 

To make this work get the files from https://github.com/ivaynberg/select2 and put them in www/js/

Then put the following in a file in www/js/myselect2.js where tool is your shiny selectInput

<link href="js/select2.css" rel="stylesheet"/>
<script src="js/select2.js"></script>
<script>
    $(document).ready(function() { $("#tool").select2({ width: 'resolve' }); });
</script>

Then in ui.R

includeHTML("www/js/myselect2.js"),
selectInput(inputId = "tool", label = "Tool:", choices = toolChoices, selected = 'Data view')

Question: Is it possible in a shiny selectInput to use optgroup to help split up longer lists of option values (see example below from the select2 page)?

<optgroup label="Alaskan/Hawaiian Time Zone">
<option value="AK">Alaska</option>
<option value="HI">Hawaii</option>
</optgroup>

John Reeder

unread,
Jan 17, 2013, 1:05:50 PM1/17/13
to shiny-...@googlegroups.com
That's really great. Thanks for passing along.

--
 
 

Message has been deleted

John Reeder

unread,
Jan 31, 2013, 11:06:44 PM1/31/13
to shiny-...@googlegroups.com, ree...@svn.com
Ahhh...

Please disregard my question.  I just saw your post and looked at what you had on github.  I now have it working correctly.  Thanks so much.  Looks great.

Joe Cheng

unread,
Feb 5, 2013, 3:37:23 AM2/5/13
to shiny-...@googlegroups.com
Vincent, looks like this message can be disregarded, it was posted 5 days late because Google Groups thought it was spam for some reason. Sorry John.


On Thu, Jan 31, 2013 at 7:44 PM, John Reeder <jreed...@gmail.com> wrote:
Vincent-

I finally got around to trying out the select2 code you posted and I'm having an issue.  I have a shiny app posted here:

http://198.58.103.208:3838/wrARB2/

And I was hoping to use select2 for the name selection.

The following is the code from ui.R

library(shiny)

wrSum12 <- read.csv("/usr/local/lib/R/wrSum12_arb.csv")
includeHTML("/var/shiny-server/www/js/myselect2.js")

# Define UI for dataset viewer application
shinyUI(pageWithSidebar(

  headerPanel("ADP Arbitrage"),
  
  sidebarPanel(
    selectInput(inputId="PID", label="Wide Receiver", choices = unique(wrSum12$NAME),selected="Ty Hilton")
  ),
  
  mainPanel(
    
    h2(textOutput("subjADP")),
    tableOutput("subject"),
    h2(textOutput("simADP")),
    tableOutput("sims")

    )
  
  ))

I also created the myselect2.js file that you suggested and it's sitting in the www/js folder as well.

But as you can see, the select2 input doesn't seem to be working.  I'm wondering if I've done something wrong that would be obvious to you.

Thanks so much for your help.


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

John Reeder

unread,
Feb 5, 2013, 11:28:05 AM2/5/13
to shiny-...@googlegroups.com
Yeah, disregard.  Got it figured out.  Thanks again for the help from both of you.

S R

unread,
Apr 23, 2013, 9:36:39 PM4/23/13
to shiny-...@googlegroups.com
Hi Joe,

I'm new to both R and Shiny, and I'm wondering if there's a way to get autocomplete to work with Shiny's textInput.  I still want the user to be able to type in their own word if it's not one of the suggestions, so I don't think select2 will work for me.  How would I go about approaching this?

Thanks 

Joe Cheng

unread,
Apr 24, 2013, 1:08:37 PM4/24/13
to shiny-...@googlegroups.com
Hi there, how many suggestions are there? Are the suggestions dynamic (e.g. dependent on the values of other inputs) or a fixed set?

S R

unread,
Apr 24, 2013, 6:55:24 PM4/24/13
to shiny-...@googlegroups.com
I have multiple textInputs.  Most are not dynamic, but one is -- its suggestions should be dependent on the value of another textInput.  For each of the inputs, there are about 50 suggestions or fewer. 

Thanks!

ZJ

unread,
Dec 12, 2013, 2:27:51 PM12/12/13
to shiny-...@googlegroups.com
Check out the ShiySky package


install.packages("devtools")#if not alrady installed
devtools::install_github("ShinySky","AnalytixWare")
require(shinysky)
shinysky::run.shinysky.example()

Akshay Bhonde

unread,
Aug 23, 2016, 10:22:44 PM8/23/16
to Shiny - Web Framework for R
Hi All, 

Has anyone been able to figure this out? 
I am not able to let the user type something outside the list using shinysky's typeahead.textInput
Reply all
Reply to author
Forward
0 new messages