我正在尝试使用conditionalPanel()设计一个闪亮的ui,当我选择或取消选择例如时,该UI应该显示或隐藏。一个checkboxInput()。在下面的示例中,它看起来不错,但是当我调用shinyApp()时,仍然收到两次以下错误消息:
*Warning in if (!is.na(attribValue)) { :
the condition has length > 1 and only the first element will be used
Warning in charToRaw(enc2utf8(text)) :
argument should be a character vector of length 1*
如何在多个conditionalPanels的条件下使用input.topic1而不出现错误消息?
在我的原始代码中,我有更多元素,并且对于每个checkboxInput我都会收到两条错误消息。有时(不一致?!),UI还会仅显示所有条件面板,并且单击checkboxInputs似乎没有任何作用。在解决该问题之前,我首先要解决出现的错误消息。
示例代码:
library(shiny)
library(shinythemes)
library(shinydashboard)
library(shinyjs)
header<-dashboardHeader(title = "Example")
sidebar<-dashboardSidebar(sidebarMenu(id="sidebar_tabs",menuItem("Menu1", tabName = "Overview")))
body_overview<-tabItem(tabName = "Overview"
fluidRow(box(title ="Topic 1",width = 2,"Text",checkboxInput("topic1", "Display plot",TRUE)),
box(title ="Topic 2",width = 2,"Text",checkboxInput("topic2", "Display plot",FALSE))),
fluidRow(
conditionalPanel(condition = "input.topic1 == true",box(title="Graph 1",footer="How did the customer equity develop?",width = 8,plotOutput(hist(rnorm(500)[seq_len(5)])))),
conditionalPanel(condition = "input.topic1 == true",box(title="Parameters 1",width = 4,dateRangeInput("dates", label = h3("Date range"),format = "mm/yyyy"))),
conditionalPanel(condition = "input.topic2 == true",box(title="Graph 2",footer="How did the customer equity develop?",width = 8,plotOutput(hist(rnorm(500)[seq_len(5)])))),
conditionalPanel(condition = "input.topic2 == true",box(title="Parameters 1",width = 4,dateRangeInput("dates", label = h3("Date range"),format = "mm/yyyy"))))
)
body<-dashboardBody(tabItems(body_overview))
sdb_ui <- dashboardPage(header, sidebar,body)
shinyApp(ui = sdb_ui, server = function(input, output,session) {})
谢谢
答案 0 :(得分:0)
您收到的警告来自plotOutput
,该警告需要一个指定outputId
的字符串。最好在服务器端计算图。为了避免警告,您可以执行以下操作:
body_overview<-tabItem(tabName = "Overview",
fluidRow(box(title ="Topic 1",width = 2,"Text",checkboxInput("topic1", "Display plot",TRUE)),
box(title ="Topic 2",width = 2,"Text",checkboxInput("topic2", "Display plot",FALSE))
),
fluidRow(
conditionalPanel(condition = "input.topic1 == true",box(title="Graph 1",footer="How did the customer equity develop?",width = 8,plotOutput("hist1"))),
conditionalPanel(condition = "input.topic1 == true",box(title="Parameters 1",width = 4,dateRangeInput("dates", label = h3("Date range"),format = "mm/yyyy"))),
conditionalPanel(condition = "input.topic2 == true",box(title="Graph 2",footer="How did the customer equity develop?",width = 8,plotOutput("hist2"))),
conditionalPanel(condition = "input.topic2 == true",box(title="Parameters 1",width = 4,dateRangeInput("dates", label = h3("Date range"),format = "mm/yyyy")))
)
)
server <- function(input, output,session) {
output$hist1 <- renderPlot(
hist(rnorm(500)[seq_len(5)])
)
output$hist2 <- renderPlot(
hist(rnorm(500)[seq_len(5)])
)
}
shinyApp(ui = sdb_ui, server = server)