91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎樣用R-Shiny打造在線App

發布時間:2021-12-09 11:22:44 來源:億速云 閱讀:268 作者:柒染 欄目:大數據

怎樣用R-Shiny打造在線App,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

今天做一個小小的案例,算是shiny動態可視化的小開端……

這個案例是之前發過的中國人口結構動態金字塔圖,這個圖還是蠻不錯,數據取自UN的官網,非常有現實意義的人口性別結構數據。

library(ggplot2)

library(animation)

library(dplyr)

library(tidyr)

library(xlsx)

library(ggthemes)

library(shiny)

library(shinythemes)

做簡單的數據清洗工作,為shiny提供可用的數據源:

setwd("D:/R/File")

windowsFonts(myfont=windowsFont("微軟雅黑"))

female<-read.xlsx("Population.xlsx",sheetName="Female",header=T,encoding='UTF-8',check.names = FALSE)

male<-read.xlsx("Population.xlsx",sheetName="Male",header=T,encoding='UTF-8',check.names = FALSE)

female<-female%>%gather(Year,Poputation,-1)

male<-male%>%gather(Year,Poputation,-1)

female$Poputation<-female$Poputation*-1

male$sex<-"male";female$sex<-"female"

China_Population<-rbind(male,female)%>%mutate(abs_pop=abs(Poputation))

China_Population$agegroup<-factor(China_Population$agegroup,

levels=c("0-4","5-9","10-14","15-19","20-24","25-29","30-34","35-39","40-44","45-49","50-54","55-59","60-64","65-69","70-74","75-79","80+") ,order=T)

China_Population_dd<-filter(China_Population,Year==1995)

定制shinyapp的ui:

ui <-shinyUI(fluidPage(

theme=shinytheme("cerulean"), 

titlePanel("Population Structure Data"),

    sidebarLayout(

        sidebarPanel(

            selectInput("var1", "x-axis",c("agegroup"="agegroup","Poputation"="Poputation","sex"="sex"),selected="agegroup"),

            selectInput("var2", "y-axis",c("agegroup"="agegroup","Poputation"="Poputation","sex"="sex"),selected="Poputation"),

            selectInput("var3", "Gender",c("agegroup"="agegroup","Poputation"="Poputation","sex"="sex"),selected="sex"),

            selectInput("theme", "Choose a ShinyTheme:",choices ("cerulean","cosmo","cyborg","darkly","flatly","journal","lumen","paper",

            "readable","sandstone","simplex","slate","spacelab","superhero","united","yeti")),

            sliderInput("var4","Year",min=1950,max=2015,value=5,step=5)

         ),

         mainPanel(h3('Dynamic pyramid of population structure in China'),plotOutput("distPlot"))

    )

))

定制shiny的輸出服務端:

server<-shinyServer(function(input,output){

    output$distPlot <- renderPlot({

    mydata=filter(China_Population,Year==input$var4)

    argu1<-switch(input$var1,agegroup=mydata$agegroup,Poputation=mydata$Poputation,sex=mydata$sex)

    argu2<-switch(input$var2,agegroup=mydata$agegroup,Poputation=mydata$Poputation,sex=mydata$sex) 

    argu3<-switch(input$var3,agegroup=mydata$agegroup,Poputation=mydata$Poputation,sex=mydata$sex) 

    ggplot(data=mydata,aes(x=argu1,y=argu2,fill=argu3))+

        coord_fixed()+ 

        coord_flip() +

        geom_bar(stat="identity",width=1) +

        scale_y_continuous(breaks = seq(-70000,70000,length=9),

                         labels = paste0(as.character(c(abs(seq(-70,70,length=9)))), "m"), 

                         limits = c(-75000,75000)) +

        theme_economist(base_size=14)+ 

        scale_fill_manual(values=c('#D40225','#374F8F')) + 

        labs(title=paste0("Population structure of China:",input$var4),

        caption="Data Source:United Nations Department of Economic and Docial Affairs\nPopulation Division\nWorld Population Prospects,the 2015 Revision"

        ,y="Population",x="Age") + 

        guides(fill=guide_legend(reverse=TRUE))+

        theme(

             text=element_text(family="myfont"),

             legend.position =c(0.8,0.9),

             legend.title = element_blank(),

             plot.title = element_text(size=20),

             plot.caption = element_text(size=12,hjust=0)

         )

  })

})

運行app:

shinyApp(ui=ui,server=server)

怎樣用R-Shiny打造在線App

看完上述內容,你們掌握怎樣用R-Shiny打造在線App的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

app
AI

洛浦县| 河南省| 宁津县| 温宿县| 裕民县| 三原县| 独山县| 同仁县| 舞阳县| 阳城县| 华蓥市| 汤阴县| 读书| 惠来县| 前郭尔| 湖口县| 沙雅县| 方正县| 天门市| 石阡县| 马龙县| 奇台县| 河间市| 达拉特旗| 内乡县| 华宁县| 连平县| 昭觉县| 临桂县| 即墨市| 四平市| 句容市| 乌审旗| 洱源县| 枣庄市| 鄂尔多斯市| 腾冲县| 冀州市| 景洪市| 瑞金市| 仲巴县|