Вот кое-что, что будет работать.Вам необходимо динамически визуализировать selectInput
на основе узлов.
library(shiny)
server <- function(input, output) {
# minimal example
nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))
output$network_proxy_nodes <- renderVisNetwork({
visNetwork(nodes, edges) %>% visNodes(color = "blue")
})
observeEvent(input$Focus, {
visNetworkProxy("network_proxy_nodes") %>%
visFocus(id = input$Focus, scale = 4)
})
observeEvent(input$color, {
visNetworkProxy("network_proxy_nodes") %>%
visNodes(color = input$color)
})
output$choose_node <- renderUI({
selectInput("Focus", "Focus on node :",
nodes$id)
})
}
ui <- fluidPage(
fluidRow(
column(
width = 4,
selectInput("color", "Color :",
c("blue", "red", "green"))
),
column(
width = 8,
visNetworkOutput("network_proxy_nodes", height = "400px"),
uiOutput("choose_node")
)
)
)
shinyApp(ui = ui, server = server)
РЕДАКТИРОВАТЬ
После вашего комментария добавьте кнопку.
library(shiny)
server <- function(input, output) {
# minimal example
nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))
output$network_proxy_nodes <- renderVisNetwork({
visNetwork(nodes, edges) %>% visNodes(color = "blue")
})
observeEvent(input$focus_now, {
visNetworkProxy("network_proxy_nodes") %>%
visFocus(id = input$Focus, scale = 4)
})
observeEvent(input$color, {
visNetworkProxy("network_proxy_nodes") %>%
visNodes(color = input$color)
})
output$choose_node <- renderUI({
selectInput("Focus", "Focus on node :",
nodes$id)
})
}
ui <- fluidPage(
fluidRow(
column(
width = 4,
selectInput("color", "Color :",
c("blue", "red", "green"))
),
column(
width = 8,
visNetworkOutput("network_proxy_nodes", height = "400px"),
uiOutput("choose_node"),
actionButton("focus_now", "FOCUS")
)
)
)
shinyApp(ui = ui, server = server)