How does shinyFeedback take precedence over custom CSS styles?

Objective:
Within my application, users are required to upload a file in .csv format. If they attempt to upload a file that is not in the correct format, an alert message (showFeedbackWarning()) should be displayed near the fileInput() element. Once the user corrects their input by uploading a valid .csv file, the alert message should disappear (hideFeedback()). This functionality is currently functioning as intended in the app. Now, I aim to alter the color of the progress bar within the fileInput() section to red, similar to the example shown in this reference. However, I want to maintain the default orange color for the warning message.

Issue:
The custom CSS introduced by shinyFeedback seems to override my style changes, preventing the progress bar color from updating. While using !important may temporarily resolve the issue, it also affects the color of the bar in the warning message, which is undesirable.

If you have any insights or solutions to address this challenge, please share them.

Example:

library(shiny)
library(shinyFeedback)

ui <- fluidPage(
  useShinyFeedback(),
  fileInput(
    inputId = "upload",
    label = "Choose File:",
    accept = ".csv"
  ),
  tags$style(".progress-bar {
             background-color: red;
             }"),
  verbatimTextOutput("text")
)

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

  data_in <- reactive({
    req(input$upload)
    ext <- tools::file_ext(input$upload$name)

    if (ext == "csv") {
      hideFeedback("upload")
      read.delim(
        input$upload$datapath,
        sep = ";"
      )
    } else {
      showFeedbackWarning(
        inputId = "upload"
      )
    }
  })

  output$text <- renderPrint({
    class(data_in())
  })
}

shinyApp(ui, server)

Answer №1

To create dynamic color changes, we can utilize the shinyjs package:

library(shiny)
library(shinyjs)
library(shinyFeedback)

ui <- fluidPage(
  useShinyFeedback(),
  useShinyjs(),
  fileInput(
    inputId = "upload",
    label = "Upload file:",
    accept = ".csv"
  ),
  
  verbatimTextOutput("text")
)

server <- function(input, output, session) {
  
  data_in <- reactive({
    req(input$upload)
    ext <- tools::file_ext(input$upload$name)
    
    if (ext == "csv") {
      hideFeedback("upload")
      runjs('document.querySelector("#upload_progress > div").style.setProperty("background-color", "green", "important");')
      read.delim(
        input$upload$datapath,
        sep = ";"
      )
    } else {
      showFeedbackWarning(
        inputId = "upload",
        color = "red"
      )
    }
  })
  
  output$text <- renderPrint({
    class(data_in())
  })
}


shinyApp(ui, 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

Display webpage in a fancybox

I've searched extensively for sample cases on the internet, but unfortunately, I couldn't locate any. Is there a way to upload a fresh HTML file using fancybox? $('#Create').click(function() { $.fancybox({ What content should be in ...

Scrollbar is always visible on Angular Flex Layout

As someone who is just starting to work with Angular and flex layout, I have a simple page setup consisting of a header with a side navbar and router outlet. I encountered an issue where my page always displays a scrollbar. If I remove fxFlexFill, the sc ...

Generating duplicate rows in R using the tidyverse package by repeating observations based on a specified variable

I have a dataframe in R that contains measurements for each unique ID, with both "start" and "end" values provided. The smallest possible difference between "end - start" is set as min_sz = 2, although this specific difference may not always be present in ...

Using CSS3 to conceal overflow when applying a transform effect

I am attempting to create a basic CSS3 hover effect on an image. My goal is to have half of the image appear transparent when hovered over. For demonstration purposes, I have set it to black. <div class="section"> <img src="http://placekitten ...

Position flex-box items to align with the baseline of the final line of text within a block

I am attempting to replicate the layout shown in the final example of the image linked below using flexbox. https://i.sstatic.net/KSaig.png It seems that the align-items: baseline; property works perfectly when the blocks contain only one line of text. ...

Issue with fixed header in Vuetify v-data-table not functional

While working with the Vuetify v-data-table component, I have enabled the fixed-header property. However, I have noticed that the table header is scrolling along with the table body. I am using the latest version of Chrome. Does anyone know how to addres ...

Video Autoplay within an image carousel - A seamless integration

I need assistance embedding a YouTube video as the fourth item in a slideshow on my website, www.serenitygardenrooms.com. The slideshow should play the first three images and then autoplay the video before moving on to the next image. However, the code sni ...

Update: "Mui V5 - Eliminate collapse/expand icons in TreeView and reduce TreeItem indentation"

My current project involves Mui V5 and I am looking to customize the TreeView component. Specifically, I need to remove the collapse/expand icons as I want them to be integrated into the TreeItem label component on the left side instead of the right. Add ...

Adjust the vertical positioning according to the percentage of the width

Currently, I am attempting to modify the position of my navigation bar on the screen in relation to the screen width rather than the height. I previously attempted using top: 10% in CSS, but realized this is based on the screen's height instead of its ...

Techniques for Adding Background Color to Fieldset Border

Recently starting to learn HTML and stumbled upon a question: How can I create a background color or image for a field set border? Can I simply use regular color values, or do I need special codes for creating a background color in a field set? Any insig ...

Troubles with caching on Amazon S3

Just starting out in web development and I'm working on updating HTML and CSS files stored on Amazon S3. Our website's backend is hosted on Heroku, while the front-end is on Amazon S3. Whenever I make changes to a CSS file, I can immediately see ...

What could be the reason for as.data.frame not taking into account the column names provided

I'm determined to create a data frame in a single line with named rows and columns. While I know I can achieve this easily using colnames(forecast), I wanted to simplify it just to challenge myself. Unfortunately, the following code doesn't achi ...

Manipulate classes for buttons in a React component by adding or removing them

I'm attempting to create two buttons that will toggle their class when clicked. When button one is clicked, it should add the "active" class to itself and remove the "active" class from the sibling button. I've made some progress, but I'm e ...

What could be the reason for my Form styling failure?

Currently working on freecodecamp's portfolio creation exercise. It should be a straightforward task, but I'm facing a small issue that's puzzling me. I'm trying to remove the border and outline (when focused) from my contact-area form ...

Utilize the ::before pseudo-element exclusively for the initial node

Here is the text I need to generate : https://i.sstatic.net/HzKP9.png This represents my HTML code : <!DOCTYPE html> <head> <meta charset="utf-8"/> <link rel="stylesheet" href="style5.css"> <title& ...

In JavaScript, alert a message once all images have been clicked

I'm encountering a small issue with my javascript code. I am developing a game for a school project where the objective is to click (remove) fish using a fishing rod. However, the game does not have an end condition set up, so players cannot win. Belo ...

Title: "Discrepancy in Data Types Between Two Identical Excel Files when Imported into Data Frames"

Two Excel spreadsheets are being used, one called excel1 and the other called excel2. Both files are being read in separately but using identical functions: df1<- readxl::read_xlsx("excel1.xlsx", sheet= "Ad Awareness", skip= 7) df2<- readxl::read_x ...

Content that sticks to the footer

I've been utilizing the sticky footer solution found at: This is how the CSS appears: * { margin: 0; } html, body { height: 100%; } .wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -4em; } .footer, .push { height: 4 ...

attempting to showcase a set of 4 cards simultaneously within a single carousel interface

I've encountered an issue while trying to create a slider for my card component. Despite several attempts, I'm struggling to display them properly. Adjusting the width of Carousel inner from 100% to 25% resulted in an increased number of pages i ...

Ways to expand a column across two rows using Bootstrao 4

Although this question has been asked numerous times before, the common suggestion is to span a column by placing the other columns into an inner row. Here's an example: <div class="row"> <div class="col-12 col-md-4">logo</div> ...