R Shiny: несколько условных панелей с одинаковым условием из CheckboxInput - PullRequest
0 голосов
/ 12 сентября 2018

Я пытаюсь создать блестящий пользовательский интерфейс с помощью conditionalPanel (), который должен отображаться или скрываться при выборе или отмене выбора, например, checkboxInput ().В приведенном ниже примере это выглядит нормально, но я все еще получаю следующие сообщения об ошибках дважды, когда я вызываю функциюручное отображениеАпс ():

*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*

Как я могу использовать input.topic1 для условий нескольких условных панелей, не имеясообщения об ошибках?

В моем исходном коде у меня есть больше элементов, и для каждого checkboxInput я получаю два сообщения об ошибках.Иногда (несовместимо ?!) пользовательский интерфейс также просто отображает все условные панели, и флажок Inputs, кажется, не имеет никакого эффекта при нажатии.Прежде чем обратиться к этому, я сначала хочу решить сообщения об ошибках, которые происходят.

Пример кода:

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) {})

Спасибо

1 Ответ

0 голосов
/ 12 сентября 2018

Предупреждение, которое вы получаете от 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)
...