I have a D3tree that I would like to output in my Rshiny but it does not seem to work. I tried plotting on a normal R script and it works. Tried to change the Render option but it does not work either. Anyone could possibly share why the following code would not output the map?
UI
library(shiny)
library (igraph)
library (tidygraph)
library (ggraph)
library (plotly)
library (tmap)
library (tidyverse)
library (sf)
library (patchwork)
library (ggstatsplot)
library (gapminder)
library (d3treeR)
library(treemap)
library(r2d3)
interaction <- readRDS("data/participant_interaction.rds")
interaction_all <- readRDS("data/participant_interaction_all.rds")
total_data <- read_rds('data/total_data.rds')
buildings <- read_sf("data/Buildings.csv",
options = "GEOM_POSSIBLE_NAMES=location")
resto_month2 <- read_rds('data/resto_month2.rds')
total_data_sf <- st_as_sf(total_data)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
tabsetPanel(
tabPanel( "Social Interaction",
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
helpText(" Visualise the Social Network Interaction of the Population
in Ohio"),
selectInput(inputId = "Category",
label = "Choose a Category",
choices = c( "Household Size" = "Household_Size",
"Have Kids" = "Have_Kids",
"Education Level" = "Education_Level",
"Interest Group" = "Interest_Group",
"Age Group" = "Age_Group"
),
selected = "Household_Size")
),
mainPanel(
plotOutput("treemapPlot")
)
)
),
dataset <- reactive({
interaction_all %>%
group_by(Participant_ID,MonthYear, .data[[input$Category]])%>%
summarise(InteractionCount = n()) %>%
ungroup
})
output$treemapPlot <- renderD3tree3({
d3tree3(
treemap(dataset(),
index = c(input$Category,"Participant_ID"),
vSize = "InteractionCount",
type = "index",
palette = "Set2",
align.labels=list(
c("center", "center"),
c("right", "bottom")
)),
rootname = "Tree Map of Interaction Count by Participant"
)
})
The interaction count will change based on the category input.
random dput
structure(list(Participant_ID = c(1, 1, 2, 1, 2, 0, 1, 1, 1,
0, 0, 1, 1, 0, 2), MonthYear = structure(c(2023.08333333333,
2022.75, 2022.33333333333, 2022.25, 2022.83333333333, 2022.75,
2022.25, 2022.41666666667, 2022.58333333333, 2022.75, 2022.83333333333,
2022.58333333333, 2023.25, 2022.91666666667, 2022.83333333333
), class = "yearmon"), Income = c(118421.02, 118421.02, 104429,
118421.02, 104429, 134904.67, 118421.02, 118421.02, 118421.02,
134904.67, 134904.67, 118421.02, 118421.02, 134904.67, 104429
), Expenses = c(-21139.52, -21139.52, -18363.69, -21139.52, -18363.69,
-18226.85, -21139.52, -21139.52, -21139.52, -18226.85, -18226.85,
-21139.52, -21139.52, -18226.85, -18363.69), Household_Size = c(3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), Have_Kids = c(TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE), Age = c(25, 25, 35, 25, 35, 36, 25, 25, 25,
36, 36, 25, 25, 36, 35), Education_Level = c("High School or College",
"High School or College", "High School or College", "High School or College",
"High School or College", "High School or College", "High School or College",
"High School or College", "High School or College", "High School or College",
"High School or College", "High School or College", "High School or College",
"High School or College", "High School or College"), Interest_Group = c("B",
"B", "A", "B", "A", "H", "B", "B", "B", "H", "H", "B", "B", "H",
"A"), Joviality = c(0.3280865, 0.3280865, 0.39346959, 0.3280865,
0.39346959, 0.001626703, 0.3280865, 0.3280865, 0.3280865, 0.001626703,
0.001626703, 0.3280865, 0.3280865, 0.001626703, 0.39346959),
Age_Group = structure(c(2L, 2L, 4L, 2L, 4L, 5L, 2L, 2L, 2L,
5L, 5L, 2L, 2L, 5L, 4L), levels = c("20 & Below", "21-25",
"26-30", "31-35", "36-40", "41-45", "46-50", "51-55", "56-60"
), class = "factor")), row.names = c(1810L, 7870L, 12712L,
4384L, 11450L, 973L, 3175L, 4360L, 4941L, 490L, 596L, 8420L,
8559L, 670L, 9179L), class = "data.frame")