Encountered a problem while executing CSS in Shiny R

I am attempting to incorporate my css file into Shiny R. I have been able to run the application without any issues before adding the style.css file. Below are the steps I have taken:

library(shiny)
library(tidyverse)
library(leaflet)
library(leaflet.extras)

fake_data <- read.csv("https://raw.githubusercontent.com/gabrielburcea/stackoverflow_fake_data/master/gather_divided.csv")

# Define UI for application that draws a histogram
ui <- fluidPage(
    
    navbarPage("SARS-Covid-19 Symptom Mapper", 
             div(class = "outer", 
                 
                 tabPanel("Interactive map", 
                          div(class = "outer", 
                              
                              tags$head(
                                  # Include our custom CSS
                                  includeCSS("style.css")   
                              ), 
                              
                              leafletOutput("map", width = "100%", height = "95vh"),
                              
                              
                              #Floating panel 
                              absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
                                            draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
                                            width = 330, height = "auto",
                                            
                                            h2("Select symptom"),
                                            
                                            selectInput("symptom", "Select Symptom", c("Chills",
                                                                                       "Cough", "Diarrhoea",
                                                                                       "Fatigue",
                                                                                       "Headache",
                                                                                       "Loss of smell and taste",
                                                                                       "Muscle ache",
                                                                                       "Nasal congestion",
                                                                                       "Nausea and vomiting",
                                                                                       "Shortness of breath",
                                                                                       "Sore throat",
                                                                                       "Sputum",
                                                                                       "Temperature")
                                            )
                              
                              )
             
             )

server <- function(input, output) {
    
    filtered_data <- reactive({
        fake_data %>% 
            dplyr::filter(Symptom %in% input$symptom)
    })
    
    output$map <- renderLeaflet({
        
        leaflet() %>%
            addTiles() %>%
            addMarkers(data = filtered_data(), clusterOptions = markerClusterOptions())
        
    })
    
}


# Run the application 
shinyApp(ui = ui, server = server)

The error I encounter is:

Error in parse(file, keep.source = FALSE, srcfile = src, encoding = enc) : 
  /Users/myname/Rprojects/training_shiny/app.R:53:1: unexpected symbol
52: 
53: server

However, if I exclude working with css, the app runs smoothly without any issues. Specifically, if I remove the lines from navbarPage all the way to line leafletOutput, leaving the code from leafletOutput onwards, the app runs without errors. The difficulty arises when trying to implement the style.css file. For more information on how I ran the app without css, refer to this link: integrating leaflet map in RShiny - inputselect by country and symptom

Answer №1

Experiment with this complete code snippet that incorporates your style sheet named style2.css

library(shiny)
library(tidyverse)
library(leaflet)
library(leaflet.extras)

fake_data <- read.csv("https://raw.githubusercontent.com/gabrielburcea/stackoverflow_fake_data/master/gather_divided.csv")

# Setting up the UI for an application that creates a histogram
ui <- fluidPage(

  navbarPage("SARS-Covid-19 Symptom Mapper",
             div(class = "outer",
              tabPanel("Interactive map",
                div(class = "outer",
                    tags$head(
                      # Incorporating our custom CSS
                      #includeCSS("style.css")
                      tags$link(rel = "stylesheet", type = "text/css", href = "style2.css")
                    ),

                    leafletOutput("map", width = "100%", height = "95vh"),

                    # Floating control panel
                    absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
                                  draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
                                  width = 330, height = "auto",

                                  h2("Select symptom"),

                                  selectInput("symptom", "Select Symptom", c("Chills",
                                                                             "Cough", "Diarrhoea",
                                                                             "Fatigue",
                                                                             "Headache",
                                                                             "Loss of smell and taste",
                                                                             "Muscle ache",
                                                                             "Nasal congestion",
                                                                             "Nausea and vomiting",
                                                                             "Shortness of breath",
                                                                             "Sore throat",
                                                                             "Sputum",
                                                                             "Temperature")
                                  )

                    )

                )
              )))
  )

server <- function(input, output) {
  filtered_data <- reactive({
    fake_data %>%
      dplyr::filter(Symptom %in% input$symptom)
  })
  
  output$map <- renderLeaflet({
    
    leaflet() %>%
      addTiles() %>%
      addMarkers(data = filtered_data(), clusterOptions = markerClusterOptions())
    
  })
  
}

### Running the application
shinyApp(ui = ui, server = server)

The displayed result is using your provided style sheet:

https://i.sstatic.net/pr3KR.png

This is the outcome without applying your given style sheet:

https://i.sstatic.net/GSoNn.png

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

Progress Circles on Canvas in FireFox

Currently, I am experimenting with this codepen demo that utilizes canvas to generate progress circles: The functionality functions perfectly in Chrome and Safari; however, it only displays black circles in FireFox. My knowledge of canvas is limited, so I ...

The orientation of Bootstrap flex - horizontal row or vertical column -

Bootstrap operates based on the class assigned to the parent element for flex row/column behavior. .bd-highlight { background-color: rgba(86, 61, 124, .15); border: 1px solid rgba(86, 61, 124, .15); } <link href="https://stackpath.bootstrapcdn.co ...

Animate the sliding of divs using the JavaScript animation function

I've designed some boxes that function similar to notifications, but now I want to smoothly slide them in from the left instead of just fading in. I know that I need to use .animate rather than .fadeIn to achieve this effect. The code snippet I&apos ...

Add a value to every element in an array

Is it possible to add 5 to each element of an array without using a loop in R? I want the resulting array to maintain the same dimensions, but with 5 added to each element. I have tried using the sum and apply functions, but encountered issues such as rece ...

Align watermark content to the far left side

Having trouble getting my watermark to align properly on the left side of my website's main content. Here is how it currently looks: https://i.sstatic.net/Nfhh5.png The issue arises when I resize the screen or switch to mobile view, as the watermark ...

Implement real-time reporting functionality in Selenium

I have been working on implementing a run-time reporting mechanism for my automated test cases created using Java with Selenium and TestNG. The test results and details are stored in a MySQL database. Although I can successfully insert the test results in ...

Navigate through the items in my subnavbar by scrolling the content

HTML Code <div id="subnavigation"> <?php $verbindung = mysql_connect("host", "user" , "pw") or die("Verbindung zur Datenbank konnte nicht hergestellt werden"); mysql_select_db("db") or die ("Datenbank konnte nicht ausgewählt w ...

Using the max-width property with Semantic UI Dropdown in ReactJS

I'm struggling to determine how to adjust the max-width of the Dropdown element in ReactJS. I attempted the following: .Menu Dropdown { max-width: 5rem !important; } Unfortunately, this did not work as expected. The dropdowns are taking up too m ...

Guide to aligning text vertically in a column alongside an image using Bootstrap 5

I have been using the Bootstrap 5.3.2 grid system for most of my website. I am trying to create a layout with an image on the left and text on the right. However, I am facing an issue with aligning the text vertically in the column. Is there a way to achie ...

Is it better to use one large CSS file for Angular 2 or opt for separate files per component

When working with Angular 2, the choice of how to style your application is an important decision. Should you create one large minified .css file using a task runner like Gulp, or use Angular 2's styleUrls: ['myfile.css'] for each component? ...

Struggling with aligning mat-icon in the center using HTML and CSS?

My issue is that the mat-icon in my generated columns is not center aligned. What could be causing this? When using ngFor to generate my datatable columns dynamically, none of them align correctly. The mat-icon inside my DIV defaults to left alignment. ...

Storing a complex array index as a variable in R

Imagine having a matrix, mat <- matrix((1:9)^2, 3, 3) You can extract specific elements from the matrix using slicing like this: > mat[2:3, 2] [1] 25 36 How can you save the subscript as a variable? If you have a variable called my_sub, how shoul ...

Is it possible to apply a click effect to a specific child element of a parent using jQuery?

Struggling to figure out how to modify this jQuery code so that only the parent of the clicked button displays its child. Currently, all children are displayed when any button is clicked, not just the one within the targeted parent. I attempted using $(t ...

What is the best way to position a popup div in CSS?

Currently, I am in the process of developing a website that displays DVD details when hovering over an image, similar to what is shown in picture 1. However, I've encountered an issue where the content gets cut off for DVDs located on the right side o ...

Preserve the PRECISE language from the R corpus

In response to the answer provided by @MrFlick on preserving document ID in R corpus: I am attempting to make some adjustments to an already excellent example. Question: How can I modify the content_transformer function to retain only exact words? The is ...

color of the foreground/background input in a dropdown menu that

I am attempting to modify the foreground or background color utilized by a dash searchable dropdown when text is entered for searching in the list. The input text is currently black, which makes it extremely difficult to read when using a dark theme. Wit ...

Use a text link to upload a file instead of using an input field

While I've seen some discussions on this topic already, the conflicting answers have left me uncertain. Is there a foolproof method for triggering file upload without using an input field? Essentially, I'd like to create a div with an icon and te ...

What causes the variation in the appearance of the navigation bar across different pages?

I'm struggling to understand why the Navigation bar has extra padding or margin on top only on certain pages, while it looks fine on the Homepage. I've dedicated countless hours to this issue and I am feeling completely frustrated. If you' ...

CSS alert problem encountered

I have an HTML and CSS notification template that I would like to incorporate into my PHP code. You can view the template here. HTML <div class="alert-box error"><span>error: </span>Write your error message here.</div> &l ...

What is the process for programmatically aligning two cards side by side using Material UI in React after retrieving data from an API?

I am currently working with data from an API that I need to display in the format of cards, arranged side by side. To achieve this, I have been using an array and passing the data to components programmatically. You can see the output image and my code bel ...