美文网首页生信可视化
R shiny的一些例子

R shiny的一些例子

作者: 小明的数据分析笔记本 | 来源:发表于2020-04-14 00:18 被阅读0次

第一个

https://datascienceplus.com/building-a-simple-sales-revenue-dashboard-with-r-shiny-shinydashboard/

image.png

代码

library(shiny)
library(shinydashboard)
library(ggplot2)
library(dplyr)

recommendation <- read.csv('recommendation.csv',stringsAsFactors = F,header=T)

header <- dashboardHeader(title="Basic Dashboard")
sidebar <- dashboardSidebar(
    sidebarMenu(
        menuItem("Dashboard",tabName="dashboard",icon=icon("dashboard")),
        menuItem("Visit-us",icon=icon("send",lib="glyphicon"),href="https://www.salesforce.com")
    )
) 
frow1 <- fluidRow(
  valueBoxOutput("value1")
  ,valueBoxOutput("value2")
  ,valueBoxOutput("value3")
)
frow2 <- fluidRow( 
  box(
    title = "Revenue per Account"
    ,status = "primary"
    ,solidHeader = TRUE 
    ,collapsible = TRUE 
    ,plotOutput("revenuebyPrd", height = "300px")
  )
  ,box(
    title = "Revenue per Product"
    ,status = "primary"
    ,solidHeader = TRUE 
    ,collapsible = TRUE 
    ,plotOutput("revenuebyRegion", height = "300px")
  ) 
)
# combine the two fluid rows to make the body
body <- dashboardBody(frow1, frow2)
ui <- dashboardPage(
    title = 'This is my Page title',
    header,
    sidebar,
    body,
    skin = "red"
)

server <- function(input, output) { 
  #some data manipulation to derive the values of KPI boxes
  total.revenue <- sum(recommendation$Revenue)
  sales.account <- recommendation %>% group_by(Account) %>% summarise(value = sum(Revenue)) %>% filter(value==max(value))
  prof.prod <- recommendation %>% group_by(Product) %>% summarise(value = sum(Revenue)) %>% filter(value==max(value))
#creating the valueBoxOutput content
  output$value1 <- renderValueBox({
    valueBox(
      formatC(sales.account$value, format="d", big.mark=',')
      ,paste('Top Account:',sales.account$Account)
      ,icon = icon("stats",lib='glyphicon')
      ,color = "purple")  
  })
  output$value2 <- renderValueBox({ 
    valueBox(
      formatC(total.revenue, format="d", big.mark=',')
      ,'Total Expected Revenue'
      ,icon = icon("gbp",lib='glyphicon')
      ,color = "green")  
  })
output$value3 <- renderValueBox({
    valueBox(
      formatC(prof.prod$value, format="d", big.mark=',')
      ,paste('Top Product:',prof.prod$Product)
      ,icon = icon("menu-hamburger",lib='glyphicon')
      ,color = "yellow")   
  })
#creating the plotOutput content
  output$revenuebyPrd <- renderPlot({
    ggplot(data = recommendation, 
           aes(x=Product, y=Revenue, fill=factor(Region))) + 
      geom_bar(position = "dodge", stat = "identity") + ylab("Revenue (in Euros)") + 
      xlab("Product") + theme(legend.position="bottom" 
                              ,plot.title = element_text(size=15, face="bold")) + 
      ggtitle("Revenue by Product") + labs(fill = "Region")
  })
output$revenuebyRegion <- renderPlot({
    ggplot(data = recommendation, 
           aes(x=Account, y=Revenue, fill=factor(Region))) + 
      geom_bar(position = "dodge", stat = "identity") + ylab("Revenue (in Euros)") + 
      xlab("Account") + theme(legend.position="bottom" 
                              ,plot.title = element_text(size=15, face="bold")) + 
      ggtitle("Revenue by Region") + labs(fill = "Region")
  })
}
shinyApp(ui,server)

运行代码

library(shiny)
runApp('first_shiny_example/')
shinydashboard帮助文档

https://rstudio.github.io/shinydashboard/index.html

shiny的许多例子

https://rstudio.github.io/shinydashboard/index.html

徐洲更的简书笔记

https://www.jianshu.com/p/e2495bbc7bd1

B站的一些视频

https://www.bilibili.com/video/BV13t41137vU?p=4

https://www.bilibili.com/video/BV1vJ411Q7yP?p=12

ggplot2画火山图的一个例子,同时还有一些其他的例子

https://bioinformatics-core-shared-training.github.io/shiny-bioinformatics/interactive-plots

ggplot2画图的,例子有些复杂

https://github.com/smouksassi/ggplotwithyourdata

40个简单的shiny小例子

http://zevross.com/blog/2016/04/19/r-powered-web-applications-with-shiny-a-tutorial-and-cheat-sheet-with-40-example-apps/

shiny gallary

https://shiny.rstudio.com/gallery/

shinyGEO

http://gdancik.github.io/shinyGEO/

https://appsilon.com/how-i-built-an-interactive-shiny-dashboard-in-2-days-without-any-experience-in-r/

欢迎大家关注我的公众号
小明的数据分析笔记本

公众号二维码.jpg

相关文章

网友评论

    本文标题:R shiny的一些例子

    本文链接:https://www.haomeiwen.com/subject/duvvmhtx.html