From fe031ae89c6b131c66621d37497e9ceb32f7f5f7 Mon Sep 17 00:00:00 2001 From: chan-ume Date: Sat, 26 May 2018 16:25:46 +0900 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shiny_sdk_toos/server.R | 74 +++++++++++++++++++++++++++++++ shiny_sdk_toos/ui.R | 97 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 shiny_sdk_toos/server.R create mode 100644 shiny_sdk_toos/ui.R diff --git a/shiny_sdk_toos/server.R b/shiny_sdk_toos/server.R new file mode 100644 index 0000000..aac35fa --- /dev/null +++ b/shiny_sdk_toos/server.R @@ -0,0 +1,74 @@ +library(shiny) + +data_rhc = read.csv("http://biostat.mc.vanderbilt.edu/wiki/pub/Main/DataSets/rhc.csv") + +shinyServer(function(input, output) { + + + data = reactive({ + switch(input$select_data, + "1" = iris, + "2" = data_rhc, + "3" = iris, + "4" = data_rhc, + "5" = iris) + }) + + data_regression = reactive({ + switch(input$select_data_regression, + "1" = iris, + "2" = data_rhc, + "3" = iris, + "4" = data_rhc, + "5" = iris) + }) + + data_clasificagtion = reactive({ + switch(input$select_data_classfication, + "1" = iris, + "2" = data_rhc, + "3" = iris, + "4" = data_rhc, + "5" = iris) + }) + + output$distPlot_shiny <- renderPlot({ + x <- faithful[, 2] # Old Faithful Geyser data + bins <- seq(min(x), max(x), length.out = input$bins_shiny + 1) + + hist(x, breaks = bins, col = 'darkgray', border = 'white') + }) + + output$histPlot <- renderPlot({ + x = data()[, input$select_columns_for_hist] + hist(x, col = 'darkgray', border = 'white') + }) + + output$scatterPlot <- renderPlot({ + x = data_regression()[, input$select_columns_for_scatter_x] + y = data_regression()[, input$select_columns_for_scatter_y] + plot(x, y, col = 'darkgray', border = 'white') + }) + + output$table = DT::renderDataTable(data(), options= list(lengthMenu = c(5, 10, 20), pageLength = 5)) + + output$plot_regression <- renderPlot({ + input$regressionButton + + x = isolate(data_regression())[, isolate(input$select_columns_for_regression_x)] + y = isolate(data_regression())[, isolate(input$select_columns_for_regression_y)] + + lm = lm(x ~ y) + plot(lm) + }) + + output$plot_classification <- renderPlot({ + input$classificationButton + + x = isolate(data_clasificagtion())[, isolate(input$select_columns_for_classification_x)] + y = isolate(data_clasificagtion())[, isolate(input$select_columns_for_classification_y)] + + lm = lm(x ~ y) + plot(lm) + }) +}) diff --git a/shiny_sdk_toos/ui.R b/shiny_sdk_toos/ui.R new file mode 100644 index 0000000..62ace15 --- /dev/null +++ b/shiny_sdk_toos/ui.R @@ -0,0 +1,97 @@ +library(shiny) + +shinyUI(navbarPage("Shinyサンプルアプリケーション", + tabPanel("Home", + headerPanel("『RとShinyで作るWebアプリケーション』のサンプルアプリケーション"), + h2("アプリケーション概要"), + p("オープンソースデータを用いて可視化と分析を行えるShinyアプリです。"), + helpText("サンプルなので、うまく動かない可能性もあるのでご注意ください。")), + + tabPanel("Shinyとは?", + headerPanel("Shinyでは以下のようなアプリケーションが作成できます。"), + sidebarLayout( + sidebarPanel( + sliderInput("bins_shiny", + "Number of bins:", + min = 1, + max = 50, + value = 30) + ), + mainPanel( + plotOutput("distPlot_shiny") + ) + )), + tabPanel("可視化",sidebarLayout( + sidebarPanel( + selectInput("select_data", label = h3("データセットを選択してください。"), + choices = list("iris" = 1, "Right heart catheterization dataset" = 2, + "Data for Titanic passengers" = 3, "Very low birth weight infant" = 4, + "Boston neighborhood housing prices data" = 5), selected = "1"), + numericInput("select_columns_for_hist", label = h3("ヒストグラムプロットするデータ列を指定。"), + value = "1"), + h3("散布図プロットするデータ列を選択。"), + numericInput("select_columns_for_scatter_x", label = h4("X軸"), + value = "1"), + numericInput("select_columns_for_scatter_y", label = h4("Y軸"), + value = "1") + ), + mainPanel( + tabsetPanel(type = "tabs", + tabPanel("Table", DT::dataTableOutput("table")), + tabPanel("ヒストグラム", plotOutput("histPlot")), + tabPanel("散布図", plotOutput("scatterPlot")), + tabPanel("みたいに他にも図を表示する") + ) + ))), + tabPanel("回帰", sidebarLayout( + sidebarPanel( + h2("回帰してみる"), + selectInput("select_data_regression", label = h3("データセットを選択してください。"), + choices = list("iris" = 1, "Right heart catheterization dataset" = 2, + "Data for Titanic passengers" = 3, "Very low birth weight infant" = 4, + "Boston neighborhood housing prices data" = 5), selected = "1"), + selectInput("select_regression", label = h3("回帰手法を選択する。"), + choices = list("重回帰分析" = 1, "ランダムフォレスト" = 2, + "3層ニューラルネット" = 3), selected = "1"), + h3("分析対象の列を選択"), + numericInput("select_columns_for_regression_x", label = h4("説明変数(「1:4」や「1, 2, 3」などの表記で複数選択可能)"), + value = "1"), + numericInput("select_columns_for_regression_y", label = h4("目的変数"), + value = "1"), + actionButton("regressionButton", "回帰!") + ), + mainPanel( + tabsetPanel(type = "tabs", + tabPanel("プロットで結果を確認", plotOutput("plot_regression")), + tabPanel("みたいな要素を表示する") + )))), + tabPanel("分類", sidebarLayout( + sidebarPanel( + h2("分類してみる"), + selectInput("select_data_classfication", label = h3("データセットを選択してください。"), + choices = list("iris" = 1, "Right heart catheterization dataset" = 2, + "Data for Titanic passengers" = 3, "Very low birth weight infant" = 4, + "Boston neighborhood housing prices data" = 5), selected = "1"), + selectInput("select_classification", label = h3("分類手法を選択する。"), + choices = list("ロジスティック回帰" = 1, "ランダムフォレスト" = 2, + "3層ニューラルネット" = 3, "SVM" = 4), selected = "1"), + h3("分析対象の列を選択"), + numericInput("select_columns_for_classification_x", label = h4("説明変数(「1:4」や「1, 2, 3」などの表記で複数選択可能)"), + value = "1"), + numericInput("select_columns_for_classification_y", label = h4("目的変数"), + value = "1"), + actionButton("classificationButton", "分類!") + ), + mainPanel( + tabsetPanel(type = "tabs", + tabPanel("プロットで結果を確認", plotOutput("plot_classification")), + tabPanel("みたいな要素を表示する") + )))), + navbarMenu("その他", + tabPanel("About", + h2("私の名前はNp-Urです。") + ), + tabPanel("ソースコード", + a(href="https://github.com/chan-ume", p("https://github.com/chan-ume"))) + ) +)) \ No newline at end of file