library(shiny) library(shinydashboard) library(leaflet) library(shinyjs) library(plotly)
ui <- dashboardPage( dashboardHeader(title = “CareNet: A Community Survival Network”), dashboardSidebar( sidebarMenu( menuItem(“Introduction”, tabName = “intro”, icon = icon(“info-circle”)), menuItem(“DISTANZ System”, tabName = “distanz”, icon = icon(“cogs”)), menuItem(“CareNet System”, tabName = “carenet”, icon = icon(“users”)), menuItem(“Interactive Map”, tabName = “map”, icon = icon(“map”)), menuItem(“Feedback”, tabName = “feedback”, icon = icon(“comment”)), menuItem(“Task Progress”, tabName = “tree”, icon = icon(“tasks”)) ) ), dashboardBody( useShinyjs(), # 使用 shinyjs 库进行动态交互 tabItems( # Introduction 页面 tabItem(tabName = “intro”, fluidRow( box(width = 12, h2(“Welcome to CareNet: A Community Survival Network”), p(“This project explores the use of surveillance systems and community-based resistance networks in a post-apocalyptic world.”), h3(“Project Overview”), p(“In the wake of environmental disasters, the world has been divided into two systems. DISTANZ controls the population with predictive safety measures, while CareNet enables grassroots community survival and mutual aid.”), plotOutput(“intro_plot”, height = “350px”), actionButton(“intro_more”, “Learn More”, icon = icon(“arrow-right”)) ) ) ),
# Learn More 页面
tabItem(tabName = "learn_more",
fluidRow(
box(width = 12,
h2("Learn More: Understanding the Systems"),
p("CareNet and DISTANZ are two contrasting systems in a post-apocalyptic world. Below, we explore how they operate, the impact they have on society, and how these systems interact."),
h3("What is DISTANZ?"),
p("DISTANZ is a predictive safety system that monitors and controls individuals in an effort to reduce the risks associated with environmental catastrophes. It uses biometric data and surveillance to regulate the movement of citizens, imposing safety zones while consolidating power into a central authority."),
h3("What is CareNet?"),
p("CareNet is a community-based survival network that emphasizes mutual aid, decentralization, and self-sufficiency. Unlike DISTANZ, CareNet focuses on solidarity and community building, where resources are shared, and people collaborate to survive."),
h3("Comparison: DISTANZ vs. CareNet"),
plotOutput("comparison_plot", height = "350px"),
actionButton("go_back", "Back to Introduction", icon = icon("arrow-left"))
)
)
),
tabItem(tabName = "distanz",
fluidRow(
box(width = 12,
h2("DISTANZ System - Surveillance and Control"),
p("DISTANZ is a surveillance system designed to monitor and predict behavior. It imposes restrictions on movement, claiming to protect citizens while consolidating power in a centralized system."),
plotOutput("distanz_plot"),
actionButton("trigger_alert", "Trigger Alert", icon = icon("exclamation-triangle"))
),
box(width = 12,
h4("Real-time Monitoring"),
dataTableOutput("user_data")
)
)
),
tabItem(tabName = "carenet",
fluidRow(
box(width = 12,
h2("CareNet System - Community Support"),
p("CareNet operates as a decentralized community survival network, providing support, resources, and mutual aid in times of crisis."),
leafletOutput("care_map"),
actionButton("request_aid", "Request Aid"),
actionButton("offer_resources", "Offer Resources")
),
box(width = 12,
h4("Community Tasks"),
dataTableOutput("community_tasks")
)
)
),
tabItem(tabName = "map",
fluidRow(
box(width = 12,
h2("Interactive Map - Locate Resources and Safehouses"),
leafletOutput("interactive_map"),
actionButton("toggle_resources", "Show Resources", icon = icon("plus")),
actionButton("toggle_hotspots", "Show Hotspots", icon = icon("fire"))
)
)
),
tabItem(tabName = "feedback",
fluidRow(
box(width = 12,
h2("Provide Feedback"),
textAreaInput("feedback_input", "Your feedback", ""),
numericInput("rating", "Rate your experience", min = 1, max = 5, value = 3),
actionButton("submit_feedback", "Submit Feedback"),
uiOutput("feedback_confirmation")
)
)
),
tabItem(tabName = "tree", # 替换树形图展示为任务进度展示
fluidRow(
box(width = 12,
h2("Community Task Progress"),
p("Here is the current progress of various community tasks. This will help you understand the effort and collaboration needed to ensure survival."),
plotlyOutput("task_progress") # 用任务进度展示替代树形图展示
)
)
)
)
) )
server <- function(input, output, session) {
# 视频播放触发 output\(video_modal <- renderUI({ if(input\)intro_video > 0) { showModal(modalDialog( title = “Introduction Video”, tags$video(src = “intro_video.mp4”, type = “video/mp4”, controls = NA, autoplay = NA), easyClose = TRUE )) } })
# DISTANZ System 模拟 observeEvent(input$trigger_alert, { runjs(“alert(‘Warning: Your actions are being monitored by the DISTANZ system!’);”) })
# DISTANZ 数据模拟 output$distanz_plot <- renderPlot({ plot(1:10, main = “Real-Time Data Monitoring (e.g. Location, Health Stats)”, col = “red”) })
output$user_data <- renderDataTable({ data.frame(User = c(“User1”, “User2”), Location = c(“Safe Zone”, “Restricted Zone”), Status = c(“Safe”, “Alert”)) })
# CareNet 系统模拟 observeEvent(input$request_aid, { showModal(modalDialog( title = “Requesting Aid”, “Your aid request has been submitted to the CareNet community.”, easyClose = TRUE )) })
observeEvent(input$offer_resources, { showModal(modalDialog( title = “Offering Resources”, “You have offered resources to the CareNet community.”, easyClose = TRUE )) })
# CareNet 地图 output$care_map <- renderLeaflet({ leaflet() %>% addTiles() %>% addMarkers(lng = 151.2093, lat = -33.8688, popup = “Safehouse: Brisbane”) %>% addMarkers(lng = 151.2153, lat = -33.8698, popup = “Water Resource”) })
# 社区任务模拟 task_data <- reactiveVal(data.frame(Task = c(“Find Water”, “Locate Shelter”), Status = c(“Pending”, “Pending”)))
observeEvent(input$trigger_task, { task_data(data.frame(Task = c(“Find Water”, “Locate Shelter”, “Find Food”), Status = c(“Completed”, “Pending”, “Pending”))) })
output$community_tasks <- renderDataTable({ task_data() })
# Interactive Map output$interactive_map <- renderLeaflet({ leaflet() %>% addTiles() %>% addMarkers(lng = 151.2093, lat = -33.8688, popup = “Safehouse: Brisbane”) %>% addMarkers(lng = 151.2153, lat = -33.8698, popup = “Water Resource”) })
# 显示资源与热点 observeEvent(input$toggle_resources, { leafletProxy(“interactive_map”) %>% addCircleMarkers(lng = 151.2093, lat = -33.8688, color = “blue”, radius = 10, popup = “Safehouse”) %>% addCircleMarkers(lng = 151.2153, lat = -33.8698, color = “green”, radius = 10, popup = “Water Resource”) })
observeEvent(input$toggle_hotspots, { leafletProxy(“interactive_map”) %>% addCircleMarkers(lng = 151.2160, lat = -33.8695, color = “red”, radius = 10, popup = “Hotspot Area”) })
# 用户反馈模拟 observeEvent(input\(submit_feedback, { showModal(modalDialog( title = "Feedback Submitted", paste("Thank you for your feedback:", input\)feedback_input, “Your rating is:”, input$rating), easyClose = TRUE )) })
# 创建任务进度图(使用 plotly) output$task_progress <- renderPlotly({ # 假设有3个任务 task_names <- c(“Find Water”, “Provide Shelter”, “Collect Food”) task_status <- c(80, 60, 40) # 用百分比表示任务的完成度
plot_ly(
type = "bar",
x = task_names,
y = task_status,
name = "Task Progress",
marker = list(color = 'rgba(0, 123, 255, 0.7)')
) %>%
layout(
title = "Task Progress",
xaxis = list(title = "Tasks"),
yaxis = list(title = "Completion Percentage (%)")
)
})
# Learn More 页面逻辑 observeEvent(input$intro_more, { updateTabItems(session, “tabs”, “learn_more”) })
observeEvent(input$go_back, { updateTabItems(session, “tabs”, “intro”) })
# 生成学习更多页面的对比图 output$comparison_plot <- renderPlot({ barplot(c(60, 80), names.arg = c(“DISTANZ”, “CareNet”), col = c(“red”, “green”), main = “Comparison of DISTANZ vs CareNet”, ylab = “Effectiveness”) }) }
shinyApp(ui = ui, server = server)
list.files(“C:/Users/coralf/Desktop/20241215/UQ/COMU3201/COMU3201.Rmd”)