Customize the appearance of checkboxInput in R Shiny using CSS

Here is a simple example of checkboxInput in shiny (a snippet from my larger code). I am looking to incorporate a CSS layout for checkboxes similar to the one showcased here. This will be my first attempt at using CSS within a shiny app, so any help with implementing this into the provided shiny code would be greatly appreciated.

ui.R

library(shiny)

shinyUI(fluidPage(

  uiOutput("checkbox")

))

server.R

shinyServer(function(input, output) {

  output$checkbox <- renderUI({

   checkboxInput('checkboxid',
                 'Check me',
                 FALSE)

  })

})

Answer №1

I have been exploring different approaches to solve this problem, but I am eager to discover a more refined solution than the one I have currently formulated. The following code is essentially a revised version of http://codepen.io/geedmo/pen/kBHsI/ from the initial query. To implement this code, copy the compiled CSS into a file named style.css and place it in the "www" folder. Additionally, the modified HTML includes the necessary attributes and tags for seamless integration with Shiny.

Here is the updated code snippet:

    library(shiny)

    ui <- shinyUI(fluidPage(
            HTML("<link rel='stylesheet' type='text/css' href='style.css'>"),

       titlePanel("Checkboxgroup"),
       fluidRow(
       HTML(
               '<div id="checkGroup" class="form-group shiny-input-checkboxgroup shiny-input-container-inline">
                            <div class="btn-switch btn-switch-primary form-group">
                                    <input type="checkbox" id="input-btn-switch-primary" name="checkGroup" value="1"/>
                                    <label for="input-btn-switch-primary" class="btn btn-round btn-primary"><em class="glyphicon glyphicon-ok"></em><strong> CLICK ME</strong></label>
                            </div>
                            <div class="btn-switch btn-switch-success  form-group">
                                    <input type="checkbox" id="input-btn-switch-success" name="checkGroup" value="2"/>
                                    <label for="input-btn-switch-success" class="btn btn-round btn-success"><em class="glyphicon glyphicon-ok"></em><strong> CLICK ME</strong></label>
                            </div>
                            <div class="btn-switch btn-switch-info  form-group">
                                    <input type="checkbox" id="input-btn-switch-info" name="checkGroup" value="3"/>
                                    <label for="input-btn-switch-info" class="btn btn-round btn-info"><em class="glyphicon glyphicon-ok"></em><strong> CLICK ME</strong></label>
                            </div>
                            <div class="btn-switch btn-switch-warning  form-group">
                                    <input type="checkbox" id="input-btn-switch-warning" name="checkGroup" value="4"/>
                                    <label for="input-btn-switch-warning" class="btn btn-round btn-warning"><em class="glyphicon glyphicon-ok"></em><strong> CLICK ME</strong></label>
                            </div>
                            <div class="btn-switch btn-switch-danger  form-group">
                                    <input type="checkbox" id="input-btn-switch-danger" name="checkGroup" value="5"/>
                                    <label for="input-btn-switch-danger" class="btn btn-round btn-danger"><em class="glyphicon glyphicon-ok"></em><strong> CLICK ME</strong></label>
                            </div>
               </div>'
       ),
       textOutput("selectedOptions")
    )

    ))


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

       output$selectedOptions <- renderText({
          paste("Selected options:", paste((input$checkGroup), collapse = " "), sep = " ")
       })
    })


    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

Retrieve the identifier of the higher-order block when it is clicked

When I have a parent block with a nested child block inside of it, I expect to retrieve the id of the parent when clicked. However, the event target seems to be the child element instead. Is there a way for JavaScript to recognize the parent as the event ...

Tips for designing resizable overlay divs

Looking to design an image with an overlay gradient and text, similar to this: <div> <img src="url"/> <div background-image="other url" background-repeat:repeat-x;> <h2>some text</h2> </div> </div> Some impor ...

What causes the disappearance of CSS styles when the IncludeStyleBlock property is set to True?

In the demo web project included in VS2010, there is a system.web.ui.webcontrols.menu control available. This specific menu has an IncludeStyleBlock property. Setting the IncludeStyleBlock property to False allows the menu to display correctly. However, ...

Creating a dynamic table using jQuery and XML content

Hello everyone, I am new to jQuery and JavaScript in general. My goal is to generate a table based on XML data, but I'm struggling to achieve the correct output. Here's what I have tried so far: Here is my HTML code: <table id="daily_fruit"& ...

Following my ajax submission, the functionality of my bootstrap drop-down menu seems to have been compromised

I'm having an issue with my login page. After implementing Ajax code for the reset password feature, the dropdown menu on the login page doesn't work properly when wrong details are entered and the page reloads. I've tried using the $(' ...

A guide on breaking down a dataset in R using a specific keyword

I have a dataset that I need to divide into multiple smaller datasets based on one variable, which may have slight variations in its values. To better explain this, consider the following example with the initial data table: +----------------------+------ ...

Executing JavaScript Code Through Links Created Dynamically

I am currently developing a website with a blog-style layout that retrieves information from a database to generate each post dynamically. After all posts are created, the header of each post will trigger an overlaid div displaying the full article for tha ...

What is the best way to validate adjusted tags within the html editor of Visual Studio 2012?

The html editor in Visual Studio 2012 keeps giving me warnings for tag names that are not recognized in the detected or configured html schema. Since I am using AngularJs by Google, this is quite inconvenient as it relies on the ability to enter custom ta ...

A simple way to add a value from a select option into a textarea when there are several dropdown menus and select elements sharing the same

I have several divs with the same class names where I need to input a value from a dropdown menu into the textarea that belongs to the div where the select element is located. I want this function to work smoothly even with more than 10 divs, which is why ...

How can I create a new div element for every item in an array by utilizing JSX?

I am currently working on creating a div element for each item in an array using reactjs JSX. I wasn't sure how to tackle this, so I attempted the following approach: {results.map((element, index) => ( <div key={index} className={ ...

Navigation menu automatically scrolls to the top instantaneously

Update: Apologies for the previous issues encountered with offline hosting. Upon transferring everything to the domain, the problem has been resolved. However, a lingering question remains about why the website loaded incorrectly when all files were kept i ...

The typical actions of the table elements

When I view my table on large screens, the TH elements are displayed at the top. However, when I switch to a mobile device, these THs move to the left side instead. Is this the default behavior of TH elements in tables? I am utilizing the 'responsive- ...

Python script using Selenium to automate a time-consuming daily task

Repeating the script below 51 times, totaling 2,300 lines of code, serves the same purpose with every block having a single line different, repeated 51 times. Now there are two main questions to address for this project: 1. How can I implement a terminal ...

How can HTML content be stored in a variable using JavaScript?

Today, I delved into JavaScript basics and managed to create a simple HTML page that allows users to add or remove list items. While I am aware that there are more advanced solutions out there, I believe that for my learning process, this accomplishment is ...

Using regular expressions in R to remove periods

How can I filter out strings with dots from a string vector obtained using list.files() in R? I tried the following code snippets without success: list.files(R.home(), pattern='[^\\.]') list.files(R.home(), pattern='[^.]') I ...

Alteration in relational shift of division placement

My webpage is divided into three sections with the following proportions: 15% - 65% - 20% In the right section, there is a div with the ID alchemy. I want to set the height of this div using <div style="height:150px;">. However, when I set the heig ...

Placing an image at the forefront of all elements

Recently, I created a horizontal opt-in bar for my Newsletter on my website. Instead of the traditional submit button, I decided to use an image by incorporating some CSS: #mc_embed_signup input.button { background: url(http://urltotheimg.com/image.jpg); ...

doMPI collaborating with nodes, processors, and cores

I am looking to conduct a distributed parallel computation using a cluster I have access to, which consists of 5 nodes. Each node is equipped with two processors (CPUs), and each processor has 18 cores. As a result, the total number of threads available f ...

In Selenium with Python, leverage CSS selectors to target specifically two classes

Imagine you have an HTML structure like this: <div class="first second"> Correct! </div> <div class="first second third fourth"> Incorrect! </div> <div class="first second"> Correct! & ...

What are the advantages of generating an HTML string on the server side and adding it to the client side?

Is there a more efficient method for transferring a large amount of data from the server to the client and dynamically generating tables, divs, and other HTML elements using JavaScript (jQuery)? Initially, I attempted to generate these elements on the cli ...