【发布时间】:2020-07-15 12:35:08
【问题描述】:
我正在尝试在 Shiny R 中运行我的 css 文件。我在没有 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 一直排除行到 lineleafletOutput,让代码从 LeafletOutput 开始,我运行我的应用程序没有问题。当我尝试添加 style.css 时会出现问题。有关如何在没有 css 的情况下运行应用程序的更多详细信息,请点击此链接:integrating leaflet map in RShiny - inputselect by country and symptom
【问题讨论】:
-
我的样式表和你发的新的一模一样。以防万一,我复制了新的并进行了测试。它仍然可以正常工作,并在我的答案中为我提供了第一张图片。如果
ui对话框位于图表的中间,我喜欢它会消失。据我所知,应该没有问题。我的 RStudio 是 1.1.453 版。这应该不是问题。 -
我的 R Studio 是 1.3.156。我不相信这是因为 R/RStudio 版本。
-
无论如何,将为此开一个新问题。