---
title: "Interactive Practice 2025"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: menu
source_code: embed
self_contained: true
theme: spacelab
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(plotly)
```
# Regressions
```{r}
plot_ly(cars, x = ~speed, y = ~dist) %>%
add_markers(
marker = list(size = 9, color = "steelblue", opacity = 0.8),
text = ~paste("Speed:", speed, "<br>Distance:", dist),
hoverinfo = "text"
) %>%
add_lines(
y = ~fitted(lm(dist ~ speed, data = cars)),
line = list(color = "firebrick", width = 3),
name = "Regression line"
) %>%
layout(
title = "Interactive Speed vs Stopping Distance",
xaxis = list(title = "Speed (mph)"),
yaxis = list(title = "Stopping Distance (ft)")
)
```
# heatmap
```{r}
plot_ly(
data = cars,
x = ~speed,
y = ~dist,
type = "histogram2d",
colorscale = "Viridis",
hovertemplate = "Speed: %{x}<br>Distance: %{y}<extra></extra>"
) %>%
layout(
title = "Continuous Interactive Heat Map",
xaxis = list(title = "Speed (mph)"),
yaxis = list(title = "Stopping Distance (ft)")
)
```
# boxplot
```{r}
# Create speed groups
cars2 <- cars %>%
mutate(speed_group = cut(
speed,
breaks = c(0, 10, 15, 20, 30),
labels = c("≤10", "11–15", "16–20", ">20")
))
# Interactive box plot
plot_ly(
data = cars2,
x = ~speed_group,
y = ~dist,
type = "box",
boxpoints = "outliers",
marker = list(
color = "rgba(31, 119, 180, 0.6)"
),
line = list(color = "rgb(31, 119, 180)"),
hovertemplate = paste(
"Speed group: %{x}<br>",
"Distance: %{y} ft<extra></extra>"
)
) %>%
layout(
title = "Interactive Box Plot of Stopping Distance by Speed Group",
xaxis = list(title = "Speed group (mph)"),
yaxis = list(title = "Stopping distance (ft)")
)
```
# Conflict Hotsopt
```{r}
hotspots <- data.frame(
location = c(
"Northern Shan State",
"Sagaing Region",
"Kachin State",
"Rakhine State",
"Kayah State"
),
lat = c(23.5, 22.0, 25.5, 20.5, 19.3),
lon = c(97.5, 95.0, 97.8, 93.0, 97.2),
intensity = c("High", "High", "Medium", "Medium", "High")
)
# Interactive map
plot_ly(
data = hotspots,
type = "scattergeo",
lat = ~lat,
lon = ~lon,
text = ~paste(
"<b>Location:</b>", location, "<br>",
"<b>Intensity:</b>", intensity
),
hoverinfo = "text",
marker = list(
size = 14,
color = c("red", "red", "orange", "orange", "red"),
opacity = 0.7,
line = list(width = 1, color = "black")
)
) %>%
layout(
title = "Interactive Map of Conflict Hotspots in Myanmar (Illustrative)",
geo = list(
scope = "asia",
center = list(lat = 21.5, lon = 96),
projection = list(type = "mercator"),
showland = TRUE,
landcolor = "rgb(240,240,240)",
countrycolor = "rgb(180,180,180)"
)
)
```
# Time series
```{r}
ts_data <- data.frame(
date = seq(as.Date("2024-01-01"), by = "month", length.out = 12),
value = c(120, 130, 128, 145, 150, 160, 158, 170, 180, 175, 185, 190)
)
plot_ly(
data = ts_data,
x = ~date,
y = ~value,
type = "scatter",
mode = "lines+markers",
line = list(
color = "steelblue",
width = 3
),
marker = list(
size = 8,
color = "steelblue"
),
hovertemplate = paste(
"<b>Date:</b> %{x}<br>",
"<b>Value:</b> %{y}<extra></extra>"
)
) %>%
layout(
title = "Interactive Time Series Trend",
xaxis = list(
title = "Time",
rangeselector = list(
buttons = list(
list(count = 3, label = "3m", step = "month", stepmode = "backward"),
list(count = 6, label = "6m", step = "month", stepmode = "backward"),
list(step = "all")
)
),
rangeslider = list(visible = TRUE)
),
yaxis = list(title = "Value")
)
```