首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在使用Shiny R运行css时出现错误

在使用Shiny R运行css时出现错误
EN

Stack Overflow用户
提问于 2020-07-15 20:35:09
回答 1查看 137关注 0票数 0

我正在尝试运行我的css文件在Shiny R。我已经成功地运行没有css。但我添加了style.css,但它不起作用。以下是我所做的工作:

代码语言:javascript
运行
复制
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)

这是我得到的错误:

代码语言:javascript
运行
复制
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

EN

Stack Overflow用户

回答已采纳

发布于 2020-07-15 22:31:29

尝试这整个代码,它将使用您的样式表作为style2.css

代码语言:javascript
运行
复制
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)

以下输出包含在样式表中:

这没有你的样式表:

票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62914978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档