自动完成和多值的文本框中选择有光泽 [英] Auto complete and selection of multiple values in text box shiny

查看:439
本文介绍了自动完成和多值的文本框中选择有光泽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用类似自动完成字符串谷歌搜索和堆栈溢出闪亮的文本框中选择标记选择多值。

Is it possible to select multi values using auto complete strings similar to google search and stack overflow tags selection in shiny text box.

dataset<-cbind("John Doe","Ash","Ajay sharma","Ken Chong","Will Smith","Neo"....etc)

我要选择从上面的数据集多个变量作为自动填写我的文本框,并把它传递给我的server.R

I want to select multiple variables from the above dataset as a auto fill in my textbox and pass it to my server.R

ui.R

shinyUI(fluidPage(
  titlePanel("test"),

  sidebarLayout(
    sidebarPanel(
      helpText("text"),

      textInput("txt","Enter the text",""),
      #Pass the dataset here for auto complete

     ),

    mainPanel(
      tabsetPanel(type="tab",tabPanel("Summary"),textOutput("text2"))

    )
  )
))

server.R

server.R

# server.R

shinyServer(function(input, output) {

output$text2<- renderText({
paste("hello",input$txt)

 })


}
)

EDITED

EDITED

我用的 select2input 从shinysky选择mulitiple varialbes,但现在我已经加入提交按钮即可选择的值在一起。

I have used select2input from shinysky for selecting mulitiple varialbes but now I have added submit button to get selected values together.

#ui.R
select2Input("txt","This is a multiple select2Input",choices=c("a","b","c"),selected=c("")),

actionButton("go","submit") 

我要绑定选择的选项可以说,用户选择A和C,然后新的变量是

I want to bind selected option lets say user selected a and c then new variable is

#server.R
input$go #if pressed submit button
var<-cbind("a","c")
output$text<-renderText({ print ("var")})

但这不工作

推荐答案

。看看 shinysky 包和 textInput.typeahead 。您可以进一步自定义的风格的TextInput 自己。 修改我添加例如使用 select2Input shinysky 包还参考

Look into shinysky package and textInput.typeahead. You can further customize the style of the textinput yourself. I added example with select2Input from the shinysky package also for reference

rm(list = ls())

library(shinysky)
library(shiny)

my_autocomplete_list <- c("John Doe","Ash","Ajay sharma","Ken Chong","Will Smith","Neo")

ui <- shinyUI(
  fluidPage(tags$style(type="text/css",".shiny-output-error { visibility: hidden; }",".shiny-output-error:before { visibility: hidden; }"),
            tags$style(type="text/css","#search { top: 50% !important;left: 50% !important;margin-top: -100px !important;margin-left: -250px 
                       !important; color: blue;font-size: 20px;font-style: italic;}"),         

            mainPanel(  
              # one way of doing it
              textInput.typeahead(id="search",
                                  placeholder="Type your name please",
                                  local=data.frame(name=c(my_autocomplete_list)),
                                  valueKey = "name",
                                  tokens=c(1:length(my_autocomplete_list)),
                                  template = HTML("<p class='repo-language'>{{info}}</p> <p class='repo-name'>{{name}}</p>")
              ),
              br(),br(),
              # using select2Input
              select2Input("select2Input1","",choices=c(my_autocomplete_list),type = c("input", "select"))
              )
  )
)

server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)

在这里输入的形象描述

在这里输入的形象描述

编辑2为每个请求即可。请把在前pressions你的对象,像我一样例如 VAR&LT; - 反应({...})这样你就可以重新使用那些后来

Edit 2 as per request. Please wrap your objects in a reactive expressions as I did e.g. var <- reactive({...}) so you can re-use those later

rm(list = ls())

library(shinysky)
library(shiny)

my_autocomplete_list <- c("John Doe","Ash","Ajay sharma","Ken Chong","Will Smith","Neo")

ui <- shinyUI(
  fluidPage(sidebarPanel(select2Input("txt","",choices=c("a","b","c"),selected=c("")), br(),actionButton("go","submit"), width =2),
            mainPanel(textOutput('text'))
  )
)

server <- function(input, output, session) {

  var <- reactive({
    if(input$go==0){return()}
    isolate({
      input$go
      cbind("a","c")
    })
  })  
  output$text <- renderText({var()})
}
shinyApp(ui = ui, server = server)

这篇关于自动完成和多值的文本框中选择有光泽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆