-1

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? 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

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 !

Even with the solution that some of you has proposed to work with color codes as names to colors I still get errors

Ali Fradi
  • 110
  • 1
  • 10

1 Answers1

0

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.

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.

jntrcs
  • 527
  • 1
  • 5
  • 13
  • The problem here is I really can't get the passed value as datatable does not accept a table of one dimension which is colorList! how should I recuperate selected values? – Ali Fradi Jul 22 '18 at 00:49
  • I tried this one but I get the following error:no applicable method for 'filter_' applied to an object of class "character" And here is the code I used output$myColors <- DT::renderDataTable({ x<-filter(names(colorList),colorList==input$couleurs) DT::datatable(data =x) }) – Ali Fradi Jul 22 '18 at 05:14
  • Will you add observeEvent(input$couleurs, {print(input$couleurs)}) to your server code and see what prints out each time you change your input? – jntrcs Jul 22 '18 at 14:47
  • Nothing is happening really! I would update the question with full code – Ali Fradi Jul 22 '18 at 18:11
  • 1
    I'm sorry, the code you currently have posted has an empty server function. Of course nothing is happening if you haven't implemented a server function. If you don't understand why you need a server function you really should take the time to watch RStudio's Shiny tutorial (https://shiny.rstudio.com/tutorial/). It's two hours but will pay off in the long run. – jntrcs Jul 22 '18 at 22:11
  • Well I made it empty to avoid running errors for those who copy the code! It wasn't empty! the problem I'm facing is : I don't know which method to choose cause each one has it's probelms and I can't post both of them in just on question! thats why I tried to make it clearer. If you wand to add the code you suggested in the server function-like I did- nothing will happen ! – Ali Fradi Jul 22 '18 at 22:54