R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

menginstal packages

library(shiny)
## Warning: package 'shiny' was built under R version 4.4.2
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.4.2
library(DT)
## Warning: package 'DT' was built under R version 4.4.2
## 
## Attaching package: 'DT'
## The following objects are masked from 'package:shiny':
## 
##     dataTableOutput, renderDataTable
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

membuat data map

 # memasukkan data
covid_data <- data.frame(
  location = c("Jakarta", "Surabaya", "Medan", "Bandung", "Kudus"),
  latitude = c(-6.21, -7.25, 3.59, -6.91, -6.78),
  longitude = c(106.85, 112.75, 98.67, 107.61, 110.88),
  cases = c(50000, 30000, 20000, 25000, 15000)
)

# Define UI
ui <- fluidPage(
  titlePanel("Dashboard Penyebaran COVID-19 by Mafaza"),
  
  sidebarLayout(
    sidebarPanel(
      h4("Filter Data"),
      sliderInput("caseFilter", "Jumlah Kasus Minimal:",
                  min = 0, max = max(covid_data$cases), value = 10000)
    ),
    mainPanel(
      tabsetPanel(
        tabPanel("Peta Penyebaran", leafletOutput("covidMap", height = 500)),
        tabPanel("Data Tabel", DTOutput("covidTable"))
      )
    )
  )
)

# Define server
server <- function(input, output, session) {
  # Filtered data reactive
  filteredData <- reactive({
    covid_data %>% filter(cases >= input$caseFilter)
  })
  
  # Render Leaflet map
  output$covidMap <- renderLeaflet({
    leaflet(filteredData()) %>%
      addTiles() %>%
      addCircleMarkers(
        ~longitude, ~latitude,
        radius = ~sqrt(cases) / 100, # Scaling circle size
        color = "red",
        popup = ~paste0("<strong>Location: </strong>", location,
                        "<br><strong>Cases: </strong>", cases)
      )
  })
  
  # Render Data Table
  output$covidTable <- renderDT({
    datatable(filteredData(), options = list(pageLength = 5))
  })
}

# Run the app
shinyApp(ui, server)
Shiny applications not supported in static R Markdown documents