我正在尝试运行我的css文件在Shiny R。我已经成功地运行没有css。但我添加了style.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")
# 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)这是我得到的错误:
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然而,如果我排除使用css,我在运行这个应用程序时没有问题。如果您从navbarPage一直到leafletOutput行都排除了这些行,让leafletOutput中的代码继续运行,那么在我尝试添加app.The时,运行style.css是没有问题的。有关如何在没有css的情况下运行应用程序的更多详细信息,请按此链接:integrating leaflet map in RShiny - inputselect by country and symptom
发布于 2020-07-15 22:31:29
尝试这整个代码,它将使用您的样式表作为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")
# 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")
tags$link(rel = "stylesheet", type = "text/css", href = "style2.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)以下输出包含在样式表中:

这没有你的样式表:

https://stackoverflow.com/questions/62914978
复制相似问题