2016-05-02 6 views
1

私はリーグのデータをフィルタリングできる光沢のあるアプリを作成しようとしています。これは私のラインを示し光沢のある選択パラメータをリンクする

library(shiny) 

shinyServer(function(input, output) { 

output$distPlot <- renderPlot({ 

list <- c(2.3, 2.5, 2.6, 2.8, 4.12, 5.3, 6.2, 8.2) 
team <- c("A", "A", "A", "A", "B", "B", "B", "B") 
time <- c(1,2,3,4,5,6,7,8) 
league <- c("A", "B","A", "B","A", "B","A", "B") 

df <- data.frame(list, team, time, league) 
ggplot(df, aes(x = time, y = list, colour = team)) + geom_line() 
}) 
}) 

#ui script 
shinyUI(fluidPage(
titlePanel("Basic widgets"), 

fluidRow(

    column(3, 
     h3("Buttons"), 

     selectInput("select", label = h3("Select box"), 
        choices = list("Choice 1" = 1, "Choice 2" = 2), selected = 1)), 

    mainPanel(
    plotOutput("distPlot") 
    ) 
) 
)) 

そしてサーバースクリプト:今、次のスクリプトを使用してデータをプロット

list <- c(2.3, 2.5, 2.6, 2.8, 4.12, 5.3, 6.2, 8.2) 
team <- c("A", "A", "A", "A", "B", "B", "B", "B") 
time <- c(1,2,3,4,5,6,7,8) 
league <- c("A", "B","A", "B","A", "B","A", "B") 

df <- data.frame(list, team, time, league) 

イム:これは、データセットの例です。両方のリーグ。しかし、私が達成したいのは、 "Choice1"と "Choice2"を選択でき、関連するデータポイントがグラフに表示されていることです。選択肢の選択肢をどのようにしてユニークなリーグの価値に結びつけることができるのですか?

答えて

0

予想される出力が何であるかは完全にはわかりません。しかし、あなたが尋ねていると思うのは、selectInputの選択肢を使ってプロットを変更する方法です。

プロットをにする必要がある場合は、指定した選択肢でデータをフィルタリングします。詳細については、コードのコメントを参照してください。

注:私はsingle-file shiny app

library(shiny) 
library(ggplot2) 

ui <- fluidPage(
    titlePanel("Basic widgets"), 

    fluidRow(

     column(3, 
        h3("Buttons"), 

        selectInput("select", label = h3("Select box"), 
              choices = list("A", "B"), selected = 1, multiple = TRUE)), 

     mainPanel(
      plotOutput("distPlot") 
     ) 
    ) 
) 

server <- function(input, output) { 

    list <- c(2.3, 2.5, 2.6, 2.8, 4.12, 5.3, 6.2, 8.2) 
    team <- c("A", "A", "A", "A", "B", "B", "B", "B") 
    time <- c(1,2,3,4,5,6,7,8) 
    league <- c("A", "B","A", "B","A", "B","A", "B") 

    df <- data.frame(list, team, time, league) 

    output$distPlot <- renderPlot({ 

     ## make the plot reactive depending on the input of the selectInput 'select'. 
     df_plot <- df[df$league %in% input$select, ] 
     ## every time you make a change to selectInput 'select', this plot will update 

     ggplot(df_plot, aes(x = time, y = list, colour = team)) + 
      geom_line() 

    }) 
} 

shinyApp(ui = ui, server = server) 
にあなたのアプリを作りました
関連する問題