我对R还是比较陌生,我想知道如何创建闪亮的反应性图形。我正在尝试构建一个能够分析Airbnb数据的闪亮应用程序。总的来说,我想可视化一个双向网络,该网络以交互方式显示公寓的listing_id和评论者的reviewer_id之间的联系。
我试图将图形基于反应性过滤器,该过滤器根据邻域(来自UI的输入)过滤数据。图表本身应显示基于常见评论者ID的listing_id之间的联系(即,如果列表A具有至少一个共同的评论者,则列表A连接到列表B)。
到目前为止,我的代码是:
#---------------UI----------
ui <- fluidPage(
sidebarLayout(position = "right",
sidebarPanel(h3("Input Parameters"),
selectInput("neighborhood.selection", "Select the neighborhood you want to display",
c("Manhattan", "Brooklyn", "Queens", "Staten Island",
"Bronx")),
#textOutput("o.neighborhood.selection"),
#selectInput("vertex.selection", "Select the Vertex you want to display",
#c("Reviewer ID" = 1, "Listing ID" = 2)),
),
mainPanel(h2("Overall Network Graph"),
plotOutput("o.big.network")
)
),
)
#-----------server----------
library(igraph)
library(shiny)
library(data.table)
library(rsconnect)
library(dplyr)
dt.merged <- readRDS("dt.merged.final.rds")
dt.merged$reviewer_id <- paste0("0", dt.merged$reviewer_id)
dt.merged <- dt.merged[1:500]
server <- function(input, output) {
dt.merged.reactive <- reactive({
req(input$neighborhood.selection)
filter(dt.merged,neighbourhood_group_cleansed %in% input$neighborhood.selection)
})
all.listings <- dt.merged.reactive()[, list(name=unique(listing_id), type=TRUE)]
all.reviewers <- dt.merged.reactive()[, list(name=unique(reviewer_id), type=FALSE)]
all.vertices <- list(all.listings,all.reviewers)
output$o.big.network <- renderPlot({
# Creating the graph
g <- graph.data.frame(dt.merged.reactive()[, list(listing_id, reviewer_id)], directed=FALSE, vertices= all.vertices)
})
}