Presentation is loading. Please wait.

Presentation is loading. Please wait.

소프트웨어시스템실습 Shiny 프로그래밍 2016. 2학기.

Similar presentations


Presentation on theme: "소프트웨어시스템실습 Shiny 프로그래밍 2016. 2학기."— Presentation transcript:

1 소프트웨어시스템실습 Shiny 프로그래밍 학기

2 Shiny Programming Shiny 란? R + Interactivity (사용자 반응 지원) + Web

3 Shiny Programming

4 Shiny Application 의 구조 Shiny App은 2가지 파일을 가짐 User-interface script
Server script

5 Shiny Application 의 구조 ui.R
The user-interface (ui) script: App의 layout, appearance를 제어

6 Shiny Application 의 구조 server.R
The server.R script: App을 구성하는 필요한 명령어를 포함

7 Shiny App.의 구동 ui.R 과 server.R이 있어야 함
runApp() 첫 번째 인자에 working directory 지정 library(shiny) runApp("App-1")

8 Shiny Application의 구동 Shiny 프레임워크상에서 개발된 R 프로그램의 구동

9 User-Interface 빌드 Layout fluidPage sidebarLayout # ui.R
sidebar와 main area로 분할하는 layout sidebarPanel, mainPanel 함수를 꼭 구현해야 함 # ui.R shinyUI(fluidPage( titlePanel("title panel"), sidebarLayout( sidebarPanel( "sidebar panel"), mainPanel("main panel") ) ))

10 User-Interface 빌드 Layout ① headerPanel ② sidebarPanel ③ mainPanel
기본적인 제목과 주제가 들어가는 곳 ② sidebarPanel mainPanel을 다룰 수 있는 컴포넌트들이 들어가는 곳 ③ mainPanel 실질적인 작업의 결과가 보여지는 곳

11 User-Interface 빌드 Headers

12 User-Interface 빌드 Formatted Text

13 User-Interface 빌드 이미지 출력

14 Control Widgets 추가 Control widgets Standard Shiny widgets

15 Reactive Output 디스플레이 목표 : 사용자가 widget의 내용을 바꾸었을 때 mainPanel의 정보가 자동으로 수정

16 Reactive Output 디스플레이 Reactive output 생성을 위한 2단계
User Interface에 R object 추가 R object를 빌드하기 위해 R 코드를 삽입

17 Reactive Output 디스플레이 Step 1: User Interface에 R object 추가 inputId
Output function creates htmlOutput raw HTML imageOutput image plotOutput plot tableOutput table textOutput text uiOutput verbatimTextOutput 입력제어 출력 *Output 함수의 첫 번째 인자인 outputId(해당 예: “text1”)를 reactive output variable의 id로 사용

18 Reactive Output 디스플레이 Step 2: R object를 빌드하기 위해 R 코드를 삽입
render function creates renderImage images (saved as a link to a source file) renderPlot plots renderPrint any printed output renderTable data frame, matrix, other table like structures renderText character strings renderUI a Shiny tag object or HTML render*함수는 { }로 둘러싸인 R expression을 인자로 가짐 R expression 수행 후, object를 return (a piece of text, a plot, a data frame, etc)

19 Reactive Output 디스플레이 App의 구동 및 Reactive output 확인 output input Server

20 Source code 보기 Showcase 모드 runApp("test", display.mode = "showcase")

21 Reactive Expressions Stock 이라는 이름의 폴더 생성
다음 파일을 다운로드: ui.R, server.R, and helpers.R. App 구동: runApp("stockVis") 1. Select a stock to examine 2. Pick a range of dates to review 3. Choose whether to plot stock prices or the log of the stock prices on the y axis, and 4. Decide whether or not to correct prices for inflation.

22 Use Reactive Expressions
Streamline 계산 문제점: “Plot y axis on the log scale” 클릭 시,renderPlot의 전체가 re-run함 getSymbols에서 yahoo finance data re-fetch

23 Use Reactive Expressions
reactive 함수를 이용하여 render*  함수처럼 R expression을 {}안에 구현 “Plot y axis on the log scale” 클릭 시, renderPlot: call dataInput() dataInput: dates 및 symb widgets 의 변경 여부를 확인 dataInput: Yahoo로부터 re-fetch되는 데이터 없이 저장된 데이터 집합을 리턴 renderPlot: 차트를 다시 그림

24 Use Reactive Expressions
Reactive expression이 다시 호출되었을 때, 저장된 값을 다시 계산해야 하는 지 확인(widget의 값이 바뀌었는가) Widget의 값이 바뀌었으면 다시 계산 그대로면 저장된 값 다시 return 불필요한 code의 re-run을 막아줌

25 빅데이터 분석을 위한 Shiny Application 실습
빅데이터 분석 어플리케이션 개발 빅데이터 분석을 위한 Shiny Application 실습

26 Iris Classification 어플리케이션

27 Iris Classification 어플리케이션
Server.R

28 Iris Classification 어플리케이션
Server.R

29 Iris Classification 어플리케이션
ui.R


Download ppt "소프트웨어시스템실습 Shiny 프로그래밍 2016. 2학기."

Similar presentations


Ads by Google