LoginSignup
1
3

More than 3 years have passed since last update.

R:shinyでwebアプリをつくる

Posted at

R(RStudio)のshinyパッケージでwebアプリっぽいものを作った時の備忘録_φ(・_・

環境

  • Mac OS X 10.12.6
  • RStudio 1.0.136

準備

  • shinyパッケージをインストール
install.packages("shiny")
require(shiny)

# URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.3/shiny_1.0.5.tgz' を試しています 
# Content type 'application/x-gzip' length 2780870 bytes (2.7 MB)
# ==================================================
# downloaded 2.7 MB

# The downloaded binary packages are in
#   /var/folders/t9/xk2j5yln4_dfmh518_4xvyw80000gn/T//RtmpmH3p3h/downloaded_packages

その1:Hello Shiny!

Shiny - GalleryShiny from RStudio(lesson1)を参考にしました。

ここでやっていること

  • Hello Shiny! 表示
  • アプリ画面上で指定した階級ヒストグラム
lesson1.R
library(shiny)

# アプリケーションの UI 定義
ui <- shinyUI(fluidPage(

  # アプリケーションタイトル
  titlePanel("Hello Shiny!"),

  # サイドバー
  sidebarLayout(
   # 階級数(bin)のためのスライダー
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),

    # 生成された分布のプロットを表示する
    mainPanel(
      plotOutput("distPlot")
    )
  )
))

# サーバロジックの定義。ヒストグラムを描く
server <- shinyServer(function(input, output) {

  # ヒストグラムを描くための式。
  # この式は renderPlot にラップされている。つまり、
  #  1) これは "reactive" であり、入力が変更されると自動的に再実行される
  #  2) この出力タイプは plot である

  output$distPlot <- renderPlot({
     x    <- faithful$waiting
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

       hist(x, breaks = bins, col = "#75AADB", border = "white",
         xlab = "Waiting time to next eruption (in mins)",
         main = "Histogram of waiting times")
  })
})

# アプリを動かす
shinyApp(ui = ui, server = server)
出力結果

スクリーンショット 2018-04-10 0.15.58.png

出来ました。

↓ 暇なときに更新したいな‥( ^ω^)↓

その2:ダッシュボードを使ってみる
その3:選択された分析コードを実行する
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3