我尝试构建一个闪亮的R。我已经成功使用堆栈溢出成员。然而,我们鼓励自己添加更多问题。我的应用程序有几个问题:
这是我所取得的成就:
library(shiny)
library(tidyverse)
library(leaflet)
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(
# Application title
h1("Symptoms accross the world"),
# Sidebar with a slider input for number of bins
leafletOutput("map"),
#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",
shiny::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"), multiple = TRUE)
)
)
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)
我已经用这段代码解决了第一个问题:
leafletOutput("map", width = "100%", height = "95vh")