Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions shiny_sdk_toos/server.R
Original file line number Diff line number Diff line change
@@ -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)
})
})
97 changes: 97 additions & 0 deletions shiny_sdk_toos/ui.R
Original file line number Diff line number Diff line change
@@ -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")))
)
))