You may find a lot of info about Shiny and Shiny tutorial in this link https://shiny.rstudio.com .
Here, I just want to show simple shiny app. In this sample we generate data, create a plot and show it in web browser.
First we need to install shiny library.
> install.packages("shiny")
Then we generate simple data frame that contains date and integer value.
dates=seq.Date(from=Sys.Date(),to=Sys.Date()+29,by="day") values=sample(100:200,30) df=data.frame(date=dates,value=values
> head(df) # just to show what we have in df date value 1 2017-05-30 200 2 2017-05-31 103 3 2017-06-01 153 4 2017-06-02 134 5 2017-06-03 114 6 2017-06-04 122 | |
Copy below source and save it in your local folder and click Run App in RStudio. Plot can be seen in your web browser.
library(shiny) dates<-seq.Date(from=Sys.Date(),to=Sys.Date()+29,by="day") values<-sample(100:200,30) df<-data.frame(date=dates,value=values) # This is UI part and shows the plot output ui<-fluidPage( titlePanel("Easy Shine Chart"), plotOutput("result") ) # This is shiny server part, plot logic is here server<-shinyServer(function(input,output) { output$result=renderPlot( { plot(df$date, df$value, xlab="date", ylab="value", type="l", col="blue") } ) }) # Creates shiny app, here we include above two objects shinyApp(ui, server)
No comments:
Post a Comment