请参见下面的可复制示例,
`library(shiny)
library(visNetwork)
library(tidyverse)
Define UI
ui <- shinyUI(fluidPage(
radioButtons(inputId = "selection", label = "Select something for drop down menu", choices = c("status choice" = "status", "method choice" = "method")),
visNetworkOutput("network")
)
)
Define server
server <- shinyServer(function(input, output) {
nodes <- tibble(
id = c("A1","A2","A3","A4","A5",
"A6","A7","A8","A9","A10"),
Status = c("Student","Doctor","Dentist","Engineer","Teacher","Student","Doctor","Dentist","Engineer","Teacher"),
Method = c("car, bike, walk","bike, car", "train, bus","walk","bus, bike", "car, bike, walk, bus, train", "train, bus", "car, bike, walk","bike, car", "car" )
)
edges <- tibble(
from = c("A1","A2","A3","A4","A5",
"A6","A7","A8","A9","A10"),
to = c("A2","A3","A4","A5",
"A6","A7","A8","A9","A10","A1"),
arrows = c("to","to","to","to","to","to","to","to","to","to")
)
output$network <- renderVisNetwork({
visNetwork(nodes, edges) %>%
visPhysics(enabled = FALSE) %>%
visEdges(smooth = FALSE)
})
observeEvent(input$selection, {
graph_proxy <- visNetworkProxy("network")
if(input$selection == "status"){
graph_proxy <- graph_proxy %>%
visOptions(selectedBy = list(
variable = "Status",
style = "width:500px",
multiple = FALSE
))
} else if(input$selection == "method"){
graph_proxy <- graph_proxy %>%
visOptions(selectedBy = list(
variable = "Method",
style = "width:500px",
multiple = TRUE
))
}
})
format positions
})
Run the application
shinyApp(ui = ui, server = server)`
我有一个与上面的应用程序非常相似的应用程序,但是当在networkProxy中使用visOptions(selectedBy)参数时,它不起作用,我的其他应用程序上的数据几乎相同,并且具有相同的“方法”列,由单个逗号“”,并带有空格“”,以使visNetwork能够识别是否存在分组,上面的代码是相同的,
但是,尽管我没有从“方法”列中获得所有值,但似乎只限于您可以选择的实际值的约70%,即使它们被所需的约定分隔开了,这是参数MULTIPLE = TRUE给出了
是否有一种方法可以解决我遇到的问题,其中仅出现“方法”列中的某些单个值,而并非我可以使用所有这些值?