Gleaming personalized select input/selectize input

I am striving to customize my Shiny select input in the following ways:

  1. Eliminate the label
  2. Set a unique background color: #2f2d57
  3. Include a placeholder
  4. Enable users to both type-in and select

Despite my efforts, I have not been successful in aligning all of the above criteria simultaneously. Please see my code below:

Data:

table <- data.frame(col1 = c(3, 4, 8, 5, 2, 6, 7))

Attempt 1

Issue: Users cannot input text and select from the selectInput field

ui <- fluidPage(
  uiOutput("container")
)
server <- function(input, output) {

  output$container <- renderUI({
    fluidRow(
      tags$style("#three_code_zip_selector {color: #ffffff; background-color: #2f2d57;}"),
      selectInput('three_code_zip_selector', NULL, choices = c("Please Select Desired Number" = "", table$col1), selectize = F)
    )
  })
}

shinyApp(ui = ui, server = server)

Attempt 2

Issue: Removing selectize = F enables users to type in the input field, but the background color remains unchanged.

ui <- fluidPage(
  uiOutput("container")
)
server <- function(input, output) {

  output$container <- renderUI({
    fluidRow(
      tags$style("#three_code_zip_selector {color: #ffffff; background-color: #2f2d57;}"),
      selectInput('three_code_zip_selector', NULL, choices = c("Please Select Desired Number" = "", table$col1))
    )
  })
}

shinyApp(ui = ui, server = server)

I also attempted using selectizeInput, but encountered the same issues as before.

Attempt 3

Issue: Users can input text, but the background color remains unchanged and there is a label at the top of selectizeInput that I wish to remove.

ui <- fluidPage(
  uiOutput("container")
)
server <- function(input, output) {

  output$container <- renderUI({
    fluidRow(
      tags$style(".selectize-dropdown-content .active {background: #2f2d57; !important;color: #ffffff; !important;}"),
      selectizeInput('three_code_zip_selector', "s", choices = c("Please Select Desired Number" = "", table$col1))
    )
  })
}

shinyApp(ui = ui, server = server)

Any suggestions on how to achieve all 4 customization rules would be greatly appreciated. Thank you in advance!

Answer №1

Here is a fantastic solution using shiny:

library(shiny)

data_table <- data.frame(column1 = c(3, 4, 8, 5, 2, 6, 7))

ui <- fluidPage(
  tags$head(tags$style(HTML('
                            #number_selector+ div>.selectize-dropdown{background: #2f2d57; color: #ffffff;}
                            #number_selector+ div>.selectize-input{background: #2f2d57; color: #ffffff;}
                            '))),
  selectizeInput(inputId = 'number_selector', label = NULL, choices = data_table$column1, selected = NULL, multiple = TRUE, options = list('plugins' = list('remove_button'), placeholder = "Please Select Desired Number", 'create' = TRUE, 'persist' = TRUE)))


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

Answer №2

Here is a demonstration showcasing the usage of the shinyWidgets package:

library(shinyWidgets)

ui <- fluidPage(
  uiOutput("container")
)

server <- function(input, output) {
  table <- data.frame(col1 = c(3, 4, 8, 5, 2, 6, 7))
  output$container <- renderUI({
    fluidRow(
      pickerInput(
        inputId = "three_code_zip_selector",
        label = NULL, 
        choices = table$col1,
        options = list(
          title = "Please Select Desired Number",
          `live-search` = TRUE,
          style = c("background: #2f2d57; color: #ffffff;"))
      )
    )
  })
}

shinyApp(ui = ui, server = server)

UPDATE: Although the code structure above resembles the one provided in the question, for this specific example, having UI elements code on the server side is unnecessary. An alternative approach is shown below:

library(shinyWidgets)

ui <- fluidPage(
  fluidRow(
    pickerInput(
      inputId = "three_code_zip_selector",
      label = NULL, 
      choices = c(3, 4, 8, 5, 2, 6, 7),
      options = list(
        title = "Please Select Desired Number",
        `live-search` = TRUE,
        style = c("background: #2f2d57; color: #ffffff;"))
    )
  )
)

server <- function(input, output) {

}

shinyApp(ui = ui, server = server)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to initiate state transition from child component to parent component using React Hooks?

In the parent component, I have the following: const [updateQuantity, quantity] = useState(1); const handleChangeQuantity = e => { console.log(e.target.value); console.log("TEST"); updateQuantity(e.target.value); }; I the ...

Javascript auto submission fails to execute following the completion of the printer script

As someone new to javascript, I have a question. I have a function called sendToQuickPrinter() that prints correctly, but after it finishes executing, I need to automatically submit a form to return to my "cart.php" page. I feel like I'm almost there, ...

Using R: separate values and transform them into column names with tidyr and regex

Exploring the intricacies of the tidyr package, I am facing a challenge where I need to work with a variable that is a combination of multiple variables. In the example provided below, my goal is to separate the variable v2 into its individual components v ...

Tips for changing the dimensions of the canvas?

I'm struggling to display a photo captured from the webcam. The sizes are not matching up, and I can't pinpoint where the size is defined in the code. https://i.stack.imgur.com/Is921.png The camera view is on the left, while the photo should be ...

Utilize AngularFire to generate a new User and invoke the factory function to showcase notifications

I recently started working with AngularJS and wanted to integrate it with AngularFire/Firebase for storing project data. I created a factory that manages notifications to be displayed in a centralized location. Here is the structure of my factory: myApp.f ...

Splitting data in NodeJS sockets

Whenever I encounter the need to divide data, my standard practice involves converting it into a string format. Here's an example of how I handle data in my function: socket.on('data', function (data) { var str = data.toString().spl ...

I am looking for a sample code for Tizen that allows scrolling of a <div> element using the bezel

Seeking a functional web application in Tizen that can scroll a div using the rotating bezel mechanism. I have dedicated several hours to getting it to work without success. I keep revisiting the same resources for the past three days: View Link 1 View Li ...

The communication between a Firefox XUL extension and a webpage

Currently developing a Firefox XUL extension and in need of incorporating interaction between the web page and the extension. For instance, whenever a link is clicked on the page, I would like to trigger a function within the XUL extension. Is there any k ...

Trigger an immediate Primefaces update using a JavaScript function

Having an issue where: upon page load, I attach a 'keypress' event listener to every input field on the page. The goal is to check for special characters in the input and remove them. Below is the function that executes on page load: function ...

Creating an adjustable fixed footer using Bootstrap 3

Struggling with the application of bootstrap styling. I have a footer with columns set as col-md-3, 3, 2, 4 which sums up to a total of 12. The issue lies in the differing content within each column. My goal is to achieve equal spacing between each div in ...

creating an HTML document with 2 interactive elements

In my app.js file, I have defined routes using Angular and included references to HTML files. However, when I run the file, it only displays two controls instead of what is expected. Below is a snippet from my login.html file: ![<!DOCTYPE html> < ...

Using BeautifulSoup to Retrieve JPEG from an Image Tag's Src Attribute

Struggling with scraping this webpage for personal use. I am having trouble extracting the thumbnails of each item on the page. Despite being able to see image tags containing the required .jpgs when using "inspect" to view the html DOM, I cannot find the ...

Optimal method for passing a variable to external PHP code

I have encountered difficulties in getting my code to work, and I am seeking guidance on the correct approach to take. The issue lies within a page that contains a dynamically generated select box populated with names from a MySQL database. The select box ...

Utilizing Jquery for event handling in dynamically created table rows in a datatable

I am attempting to incorporate a function call "onblur" where I can input a new value in the TD cell. What I am looking to achieve is for the new value to be passed by the function to another JQuery script. Unfortunately, the datatable does not seem to rec ...

(MUI Textfield) Error: Unable to access properties of undefined (specifically 'focus')

I have been working with the useRef hook in my Material Ui Textfield and have encountered the error Uncaught TypeError: Cannot read properties of undefined (reading 'focus'). I am unsure how to resolve this issue. Here is my current code snippet: ...

Animate elements in Vue.js when navigating between pages is a great way to enhance user

I'm looking to add animation to a specific element once the route page finishes loading. This is not related to route page transitions. I've experimented with various methods, trying to animate a progress bar based on dynamic data values. I attem ...

Serverless Functions in ZEIT Now - Customizing Routes with Parameters

I successfully implemented 4 serverless routes /api/list (GET) /api/add (POST) /api/update/:id (PUT) /api/remove/:id (DELETE) These routes were added to the api/now.json file in the following format: {"src": "/api/list", "dest": "./list.js", "methods": ...

Can you explain the variance between using querySelector() and getElementById/getElementsByClassName/getElementsByTagName()?

I'm confused about the distinction between using querySelector() and getElementById(). From what I understand, querySelector is able to retrieve an element using any selector, giving it more flexibility. Are there additional contrasts between the two ...

Incorporate a progress bar and delete functionality for uploading files in PHP

I am currently working on creating a file uploader that includes a progress bar and a close button. However, I have encountered some major issues with the code. The progress bar continues to show endlessly, and the main problem is that it deletes the file ...

Angular's parent div height can be adjusted using CSS transitions

I have implemented a CSS transition to create a sliding effect in my pagination. However, I am facing an issue where the height of the containing div changes even when I set the position of the transitioned elements. Here is a snippet of my CSS: .slide { ...