2017-09-11 2 views
0

나는 반짝이는 앱을 개발 중이다. 제출 버튼을 사용하여 플롯을 렌더링하고 싶습니다. 또한 사용자가 inputcheckbox를 확인하면 레이블을 인쇄하려고합니다. 버튼을 통해 플롯을 렌더링 할 수 있습니다. 그러나 체크 박스가 선택되면 작동하지 않습니다. 내가 더 빛나는 전문가는 아니지만Shiny renderPlotly with two conditions

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

    }) 
} 

(나는 더 나은 방법이있을거야. 그건 그냥 내 머리 위로 떨어져 있습니다.)