Shiny :: Simple example

Published by onesixx on

 

Code

 

실행

console에서 

> setwd("/Users/onesixx/RScience/shiny/firstEx/")
> list.files()
[1] "server.R" "ui.R"  

> runApp()

Rstudio를 활용해서,

* runApp() 을  default browser대신 chrome에서 실행하고 싶은 경우,

> options(browser="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe")
> runApp()

 

결과

=======================

### First Example
library(shiny)

ui <- #shinyUI(
pageWithSidebar(
	# Application title
	headerPanel("First Example"),

	# Sidebar with a slider input for the number of bins
	sidebarPanel(
		textInput(
			inputId = "comment",
			label = "Say something?",
			value = ""
		)
	),
	mainPanel( # Show a plot of the generated distribution
		h3("this is you saying it"),
		textOutput("textDisplay")
	)
)

server <- #shinyServer(
function(input,output) {
	output$textDisplay <- renderText({
		paste0("You said '",input$comment, "'. There are ", nchar(input$comment)," characters in this")
	})
}

shinyApp(ui=ui, server=server)

 

=======================
ui.R

### First Example - ui.R
library(shiny)

# Define UI
shinyUI(pageWithSidebar(
	# Application title
	headerPanel("First Example"),

	# Sidebar with a slider input for the number of bins
	sidebarPanel(
		textInput(
			inputId = "comment",
			label = "Say something?",
			value = ""
		)
	),
	mainPanel( # Show a plot of the generated distribution
		h3("this is you saying it"),
		textOutput("textDisplay")
	)
))

server.R

### First Example - server.R
library(shiny)

# Define server logic
shinyServer(function(input,output) {

	# Expression. wrapped in a call to render function
	# "reactive" automatically re-executed when inputs change
	output$textDisplay <- renderText({
		paste0(
			"You said '",input$comment, "'. There are ",
			nchar(input$comment),
			" characters in this"
		)
	})

})

 

Categories: R-Shiny

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x