2017-09-11 62 views
0

我正在Shiny中开发应用程序。我想使用提交按钮来渲染阴谋。如果用户选中输入框,我也想打印标签。我可以通过按钮渲染图。但是当复选框被选中时它不起作用。闪亮renderLlotly有两个条件

下面是代码:

library(shiny) 
library(plotly) 

ui <- fluidPage(
actionButton('RUN', 'Run'), 
checkboxInput('PrintLab', 'Label', FALSE), 
plotlyOutput("plot1") 
) 

server = function(input, output) { 
output$plot1 <- renderPlotly({ 
req(input$RUN) 
isolate({ 
    ggplotly(ggplot(data = mtcars, aes(wt, hp)) + 
      geom_point(size=1, colour = "grey")) 
    }) 

    req(input$PrintLab) 
    isolate({ 
    ggplotly(ggplot(data = mtcars, aes(wt, hp)) + 
      geom_point(size=1, colour = "grey") + 
      geom_text(aes(label=wt), size=3, colour = "black")) 
    }) 

}) 
} 

runApp(shinyApp(ui, server)) 

回答

0

我没有闪亮的专家,但req(input$PrintLab)不正确的看向我。 这是否完成了你要去的?

server <- function(input, output) { 
    output$plot1 <- renderPlotly({ 
    req(input$RUN) 

    if (!input$PrintLab) { 
     ggplotly(ggplot(data = mtcars, aes(wt, hp)) + 
      geom_point(size=1, colour = "grey")) 
    } else { 
     ggplotly(ggplot(data = mtcars, aes(wt, hp)) + 
      geom_point(size=1, colour = "grey") + 
      geom_text(aes(label=wt), size=3, colour = "black")) 
    } 

    }) 
} 

(我敢肯定有一个更好的办法。这只是我的头顶部)。