'length(x) = 2 > 1' 强制转换为 'logical(1)'

'length(x) = 2 > 1' in coercion to 'logical(1)'

提问人:kumari sinam 提问时间:11/9/2023 更新时间:11/9/2023 访问量:59

问:

每当我在if语句中传递两个以上的条件时,我都会遇到上述错误。我也尝试了“all”而不是if语句,但它也不起作用。

错误是

distType == “All” & distType == “normal” 中的警告: 'length(x) = 2 > 1' 强制转换为 'logical(1)'

这是我的代码:

library(shiny)
library(networkD3)

添加自定义 CSS 以设置导航栏颜色和对齐方式的样式

ui = fluidPage(

sidebarLayout(
sidebarPanel(width = 3,
  selectInput("Distribution","please select"
              ,choices = c("All","normal"), multiple = TRUE, selected = "All"),
  
  
),
mainPanel(
  
  forceNetworkOutput(outputId = "net")
)

))

服务器 = 函数(输入,输出) {

Myclickaction = 'window.open(d.hyperlink, “_blank”)' output$net = renderForceNetwork({

    distType <- input$Distribution
    if(distType == "All" && distType == "normal"){

        fn <- forceNetwork(Links = MisLinks, Nodes = MisNodes,
                   Source = "source", Target = "target", charge = -150,
                   opacityNoHover = 1, Nodesize = "size",
                   Value = "value", NodeID = "name",
                   Group = "group", linkWidth = 2, clickAction =  Myclickaction,
                   opacity = 0.9,fontSize = 20, width = 1000,height = 700,linkDistance =  JS("function(d){return d.value * 40}"),colourScale =JS("d3.scaleOrdinal(d3.schemeCategory20);"),
                   zoom=TRUE)
fn$x$nodes$hyperlink <- MisNodes[["hyperlink"]]
fn
}else{

    MyClickScript <-'window.open("http://localhost:9191/"+ d.name, "_blank");'
    forceNetwork(Links = mislink, Nodes = misnod, Source = "source",
               Target = "target", Value = "value", NodeID = "name",Nodesize = "size",
               Group = "group", opacity = 1, zoom = T,opacityNoHover = TRUE,
               fontSize = 20, width = 1000,height = 700,
               bounded = TRUE, clickAction = MyClickScript,linkDistance =100)
  
  }


})

} shinyApp(ui = ui, server = 服务器)

r if-语句 shinyapps 强制

评论


答: 暂无答案