【发布时间】:2020-06-24 11:45:19
【问题描述】:
我正在创建一个闪亮的应用程序,用户可以通过单击单选按钮在不同的绘图之间切换。我在this问题中按照cmaher的建议,但发现只能切换一次。第二次给了我一个空白输出。
为什么单击按钮时闪亮的绘图输出不再渲染?以及如何做到这一点?
MWE:
server <- shinyServer(function(input, output, session) {
PlotA <- reactive({
plot(-2:2, -2:2)
})
PlotB <- reactive({
plot(-1:1, -1:1)
})
PlotInput <- reactive({
switch(input$PlotChoice,
"A" = PlotA(),
"B" = PlotB())
})
output$SelectedPlot <- renderPlot({
PlotInput()
})
})
ui <- shinyUI(fluidPage(
navbarPage(title=" ",
tabPanel("A",
sidebarLayout(
sidebarPanel(
radioButtons("PlotChoice", "Displayed plot:",
choices = c("A", "B"))),
mainPanel(plotOutput("SelectedPlot")))))
, fluid=TRUE))
shinyApp(ui=ui, server=server)
【问题讨论】: