简体   繁体   English

如何在闪亮的应用程序中将 selectInput 值读取为向量或字符?

[英]How can I read selectInput value as a vector or character in shiny app?

I'm working on a shiny app and I wonder if there is a method to recuperate the selected data by the user through selectinput as a vector or character?我正在开发一个闪亮的应用程序,我想知道是否有一种方法可以将用户通过 selectinput 作为向量或字符恢复所选数据? In fact, I typed the following code事实上,我输入了以下代码

color<-read.xlsx("colors.xlsx",startRow = 1,sheet = 1,colNames = TRUE)
myList<-color$name
ui <- fluidPage(
  sidebarLayout(
                sidebarPanel(helpText(
                  fileInput("myData", "Upload your data ")
                  sidebarPanel(
                  ),
                ),
     mainPanel(      
 # selectInput(inputId = "couleurs",label = "Select colors:",choices = myList,selected = "Dark turquoise", multiple = TRUE))
 # colourInput("col", "Select colour", "purple")
  ))
server <- function(input, output) {}
shinyApp(ui = ui, server = server)

the colors Database consists of 2 columns: the color name like Dark turquoise and code of color like "#00CED1" as follows颜色数据库由 2 列组成:颜色名称如深绿松石和颜色代码如“#00CED1”如下

Name    Code
Absolute Zero   #0048BA
Acajou  #4C2F27
Acid green  #B0BF1A
Aero    #7CB9E8
Aero blue   #C9FFE5
African violet  #B284BE
Air Force blue (RAF)    #5D8AA8
Air Force blue (USAF)   #00308F
Air superiority blue    #72A0C1
Alabama crimson #AF002A
Alabaster   #F2F0E6
Alice blue  #F0F8FF
Alizarin crimson    #E32636
Alloy orange    #C46210
Almond  #EFDECD

here I suggested whether to use the selectinput method and take the passed value which is the selected colors of use the color picker method to generate the character that regroups the selection as : '"#5D8AA8","#72A0C1"' for example the problem is I couldn't make the selection in the method 1 using the command "filter" and for the second method if I try to save the color code on color picker and paste it to the new code of color the first text changes !在这里我建议是否使用selectinput方法并获取传递的值,即使用颜色选择器方法的选定颜色来生成将选择重新组合为:'"#5D8AA8","#72A0C1"'的字符,例如问题是我无法使用命令“过滤器”在方法 1 中进行选择,对于第二种方法,如果我尝试将颜色代码保存在颜色选择器上并将其粘贴到第一个文本更改的新颜色代码中!

Even with the solution that some of you has proposed to work with color codes as names to colors I still get errors即使使用你们中的一些人建议使用颜色代码作为颜色名称的解决方案,我仍然会遇到错误

The Shiny documentation says that if you name the elements of a vector, the elements will display by name, but be sent to input$ by value. Shiny 文档说,如果您命名向量的元素,元素将按名称显示,但会按值发送到 input$。

List of values to select from.要从中选择的值列表。 If elements of the list are named, then that name rather than the value is displayed to the user.如果列表的元素已命名,则向用户显示该名称而不是值。

Therefore I would try something like因此我会尝试类似的东西

colorList<-all_codes
names(colorList)<- all_colors
selectInput(inputId = "couleurs", label = "Select colors:",choices = colorList,selected = "Dark turquoise",multiple = TRUE)

The value passed to input should be the code you need.传递给 input 的值应该是您需要的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM