静的な可視化を超えて、ユーザーが探索できるインタラクティブなダッシュボードを構築します。
Shiny、Plotly、そしてHTMLウィジェットの統合により、動的で応答性の高い分析環境を実現します。
library(shiny)
library(shinydashboard)
library(DT)
library(plotly)
ui <- dashboardPage(
dashboardHeader(
title = "CYBERPUNK ANALYTICS DASHBOARD",
titleWidth = 350
),
dashboardSidebar(
width = 300,
sidebarMenu(
menuItem("📊 Overview", tabName = "overview"),
menuItem("⚡ Analysis", tabName = "analysis"),
menuItem("🎯 Deep Dive", tabName = "deepdive")
),
selectInput(
"class_filter", "Vehicle Class:",
choices = c("All", unique(mpg$class)),
selected = "All"
),
sliderInput(
"year_range", "Year Range:",
min = min(mpg$year), max = max(mpg$year),
value = c(min(mpg$year), max(mpg$year)),
step = 1, sep = ""
)
),
dashboardBody(
tags$head(
tags$style(HTML("
body { background-color: #000000 !important; }
.content-wrapper { background-color: #000000 !important; }
.box { background-color: #1a1a1a; border: 1px solid #10d9c4; }
.box-header { color: #10d9c4; }
"))
),
tabItems(
tabItem(
tabName = "overview",
fluidRow(
valueBoxOutput("total_vehicles", width = 3),
valueBoxOutput("avg_efficiency", width = 3),
valueBoxOutput("top_class", width = 3),
valueBoxOutput("trend_analysis", width = 3)
),
fluidRow(
box(
title = "Interactive Efficiency Analysis",
status = "primary", width = 8,
plotlyOutput("main_interactive_plot")
),
box(
title = "Data Table",
status = "info", width = 4,
DT::dataTableOutput("data_table")
)
)
)
)
)
)
server <- function(input, output, session) {
filtered_data <- reactive({
data <- mpg %>%
filter(year >= input$year_range[1] &
year <= input$year_range[2])
if(input$class_filter != "All") {
data <- data %>% filter(class == input$class_filter)
}
data
})
output$main_interactive_plot <- renderPlotly({
p <- ggplot(filtered_data(), aes(displ, hwy)) +
geom_point(aes(color = class, size = cyl,
text = paste("Model:", model, "<br>",
"MPG:", hwy, "<br>",
"Displacement:", displ))) +
cyberpunk_theme
ggplotly(p, tooltip = "text") %>%
layout(
plot_bgcolor = "rgba(0,0,0,0)",
paper_bgcolor = "rgba(0,0,0,0)"
)
})
}