2017-12-16 2 views
0

Shinyapp 내가 selectInput 일부 값을 선택할 수 있습니다. 그러면 y ~ 선택된 값을 그려 봅니다. 나는 플롯 (mtcars의 $ mpg로 ~ mtcars의 $ 중량) 같은 정의 플롯을 플롯 할 수 있습니다하지만Shinyapps 플롯 SelectInput의 선택에 따라

아무도 나를 도울 수 있습니까 플롯 (mtcars의 $ mpg로 ~ 선택한 값을) 음모 wannt. renderPlot

library(shiny) 

ui <- fluidPage( 
titlePanel("MyPLot"), 
    sidebarLayout(
     sidebarPanel(
     selectInput("variable", "Variable:", c("Cylinders" = "cyl", "Transmission" = "am", "Gears" = "gear")) 
     ), 

    mainPanel(
    plotOutput("distPlot"), 
    plotOutput("secPlot") 
     ) 
    ) 
) 

server <- function(input, output) { 
    output$distPlot <- renderPlot({plot(mtcars$mpg~mtcars$wt) }) 
    output$secPlot <- renderPlot({ plot(mtcars$mpg~input$variable) }) 
} 

shinyApp(ui = ui, server = server) 
+0

이 링크 https://shiny.rstudio.com/ 시도 gallery/kmeans-example.html –

답변

1

어쩌면 당신이 mtcars 부분 집합 할 수있는 반응 데이터 프레임을 만들 수 있습니다 후 사용 : 내 코드는 이것이다

server <- function(input, output) { 
    output$distPlot <- renderPlot({plot(mtcars$mpg~mtcars$wt) }) 

    df <- reactive({ 
    df <- mtcars %>% select(mpg, input$variable) 
    }) 

    output$secPlot <- renderPlot({ 
    dfb <- df() 
    plot(dfb[, 1]~ dfb[, 2]) 
    }) 
} 

shinyApp(ui = ui, server = server) 
관련 문제