以下是我想在APP中展示的两个情节。在ui.r中,我有一个输入(绘图类型)和一个输出(绘图)。
情节类型输入:
sidebarPanel(
checkboxGroupInput("vo",
label = "Visualization Object",
choices = list("Polar Distance of VAR from nadir" = 1,
"Real Value of VAR" = 2
),
selected = c(1,2)
)
)
和情节输出:
fluidRow(
column(6,
plotOutput(outputId="polar", width = "600px", height = "600px")
),
column(6,
plotOutput(outputId="paral", width = "600px", height = "600px")
)
)
在server.r中,我使用:
if(1%in%vo){
output$polar <- renderPlot({
# input$reset
ap(whole_p[[ts$counter]])
})}
if(2%in%vo){
output$paral <- renderPlot({
# input$reset
av(whole_v[[ts$counter2]])
})}
那么如何更改服务器代码以使其工作:当我选择Polar Distance of VAR from nadir
时,只有情节output$polar
显示在ui中,而当选择Real Value of VAR
时,仅情节output$paral
显示在ui中。感谢。
答案 0 :(得分:1)
以下是基于conditionalPanel
library(shiny)
ui <- shinyUI(fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput("vo",
label = "Visualization Object",
choices = list("Polar Distance of VAR from nadir" = 1,
"Real Value of VAR" = 2
),
selected = c(1,2)
)
),
mainPanel(
conditionalPanel(condition = "input.vo.indexOf('1') >= 0", plotOutput(outputId="polar", width = "600px", height = "600px")),
conditionalPanel(condition = "input.vo.indexOf('2') >= 0", plotOutput(outputId="paral", width = "600px", height = "600px"))
)
)
))
server <- shinyServer(function(input, output) {
output$polar <- renderPlot({
plot(mtcars$mpg, mtcars$cyl)
})
output$paral <- renderPlot({
plot(mtcars$disp, mtcars$hp)
})
})
shinyApp(ui = ui, server = server)