Creating stylish action buttons in R Shiny using a customized CSS template

I am looking to customize the layout of an actionButton in a Shiny app using a CSS file. The action button is defined in server.R and used as uiOutput() in ui.R as shown below:

server.R

shinyServer(function(input, output) {
  output$ActionButtonExample <- renderUI({
      actionButton(
      inputId = "ActionButtonExample",
      label = "Accept",
      icon = icon("check"),
      width = '50%',
      style = 'float:right;'
    )
  })

})

ui.R

# Define UI for application that draws a histogram
shinyUI(fluidPage(

  # Application title
  titlePanel("Old Faithful Geyser Data"),

  # Sidebar with a slider input for number of bins 
  sidebarLayout(
    sidebarPanel(
       sliderInput("bins",
                   "Number of bins:",
                   min = 1,
                   max = 50,
                   value = 30)
    ),

    # Show a plot of the generated distribution
    mainPanel(
       uiOutput("ActionButtonExample")
    )
  )
))

Can someone provide guidance on how to customize the button using CSS similar to the example provided here: ?

Answer №1

Here's a practical illustration for implementing the button feature, with the checkboxInput following a similar process. Keep in mind that the input elements are generated server-side using uiOutput and renderUI, which means they are actually created by JavaScript on the user’s browser after the HTML document loads. Therefore, trying to use $(document).ready() or $(window).load() won't be effective. The steps outlined below illustrate how to achieve this:

  1. Upon the window load event, utilize setInterval to consistently check the page every 0.1 seconds to verify if the button has been rendered.
  2. Once the button becomes visible, stop the polling mechanism.
  3. Locate the button by its ID, and eliminate the default btn-default class (as it would render the button text in black, making it illegible).
  4. Add the necessary 3D classes to enhance the visual appearance of the button.

Snippet

library(shiny)

ui <- shinyUI(fluidPage(
  includeCSS("www/btn3d.css"),

  titlePanel("Demo Example"),

  sidebarLayout(
    sidebarPanel(
      uiOutput("button"),
      tags$head(tags$script(HTML("
         $(window).load(function() {
            var i = setInterval(function() {
              if ($('#buttonid').length) {
                clearInterval(i);
                $('#buttonid').removeClass('btn-default').addClass('btn3d btn-primary');
              }
            }, 100);
         });
      ")))
    ),

    mainPanel(

    )
  )
))

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

  output$button <- renderUI({
    actionButton("buttonid", "buttonname")  
  })

})

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

Is it possible to include edit links to local files in an HTML report that I am creating?

Looking to enhance the readability of py.test reports that look like this: self = <test_testcenter_views.TestSiteViews testMethod=test_testcenter> def test_testcenter(self): "Test the tctr_update view." > r = self.client.get(&a ...

Tips for adjusting $(document).height() to exclude the height of hidden divs

I am facing an issue with jQuery miscalculating the space at the bottom of a page I'm working on, possibly due to hidden div layers present on the page. Is there a way for jQuery to accurately calculate the 'real' height of the page as it a ...

Using jQuery to target nested HTML elements is a great way to efficiently manipulate

Within the code below, I have a complex HTML structure that is simplified: <div id="firstdiv" class="container"> <ul> <li id="4"> <a title="ID:4">Tree</a> <ul> <li id="005"> ...

Customize material-ui button designs using styled-components

I'm currently facing an issue with overriding the border-radius of a material-ui button using styled-components. Despite setting it to 0, it's not taking effect. Here is the code snippet: import React from "react"; import styled from "styled-co ...

The bottom section is not displaying properly at the conclusion of the div slide

The division ends without displaying the footer. <div id="fullpage"> <div class="section " id="section0"> content1 </div> <div class="section " id="section0"> content1 </div> <div class="section " id="section0"> c ...

Error encountered: Index 109 - The function $.ajax(...).success is not recognized as a valid function while working with jQuery in a Node

I'm just starting to learn about jquery and have been experimenting with ajax in my recent code. Below is the snippet of what I have implemented: $(function(){ $("#status").change(function(){ if($(this).is(':checked')) ...

Identify all elements that possess a specific attribute with a precise value in jQuery, and return either true or false

I'm having a slight issue with jQuery. Below is the code in question: if ($("select[rendelo='" + rendelo + "'][nap='" + nap + "'][napszak='" + napszak + "']").val() == 0) { alert('sth'); ...

Adjusting the positioning of links with bootstrap scrollyspy

Having trouble getting the scrollyspy links to align properly in the center of the navbar. Can someone offer some assistance? Much appreciated! <ul class="nav nav-pills"> <li class="nav-item"> < ...

What is the method for normalizing data in R prior to conducting regression analyses with R?

I have a dataset with 48 observations and approximately 200 variables. The first column represents the Date, while the other 199 columns are my x variables. Before running regression analysis, I aim to standardize these variables and eliminate any outliers ...

Populate a form with data retrieved from a MySQL query result

One aspect of my project involves a specific interface called 'designation.php' that contains a form. The goal is for users to enter a 'designation code' (which serves as the primary key) and then click the 'update' button, pr ...

numbered navigation jquery plugin

Can anyone recommend a jQuery plugin or alternative solution for creating a navigation system for comments similar to YouTube? Here is the link for reference: Thank you in advance. ...

Utilizing Jquery to Swap Text with Elements from an Array

If I have the following scenario: var array = [cat, dog, fish]; var string = 'The cat and dog ate the fish.'; I intend to remove all those values from a string var result = string.replace(array,""); The resulting string would be: The and at ...

Tips for invoking a url with JavaScript and retrieving the response back to JavaScript

I am trying to make a URL call from JavaScript with a single parameter, and the URL should respond to that specific request. Here is an example of the response format: {"success":true, "result": {"token":"4fc5ef2bd77a3","serverTime":1338371883,"expireT ...

The personalized directive does not respond to modifications in attributes

I am in the process of creating a modal directive that will be used to display data tables. The directive has an attribute called modal-visible, which is initially set to false by default. If this value is true, the modal will be visible when loaded. Howev ...

The UI-SELECT feature in angular-js does not seem to be displaying

I've added the necessary ui-select js and css files to my page : <link href="assets/plugins/ui-select/select.min.css" rel="stylesheet" type="text/css" <script src="assets/plugins/ui-select/select.min.js" tyle="text/javascript" </script> ...

Troublesome display problem with photo gallery

I have encountered an issue with the image gallery in my HTML file. The images are displaying nicely, but on the second row, three of the images are slipping down. Here is a screenshot for reference: https://i.sstatic.net/YmPdv.png I attempted to address ...

Display the div only if the content matches the text of the link

Looking for a way to filter posts on my blog by category and display them on the same page without navigating away. Essentially, I want users to click on a specific tag and have all posts with that tag show up. Since the CMS lacks this functionality, I pla ...

Ensuring the accuracy of HTML sliders

I am just starting out with programming and currently working on an online experiment using Django. In our experiment, sliders are being used extensively as input devices. We are trying to figure out a way to validate the sliders to ensure that participan ...

The function driver.find_element is unable to locate an element using the "class_name" attribute

My attempt at using driver.find_element, with the "class_name" method to locate and click on a button for expanding rooms on this website resulted in an error message: raise exception_class(message, screen, stacktrace) selenium.common.exceptions.N ...

Clearly defined form field even with the inclusion of value=" "

I have a database that I am using to display data in an HTML form for user editing. <input type="text" id="name" placeholder="Name" required = "true" value = <?php if(isset($_SESSION['name'])) echo $_SESSION['name'] ;?>> ...