交互。分析。沟通。
采用一种全新的、交互式的方法来讲述你的数据故事。让用户与您的数据和分析进行交互。用R来做。


Shiny是一个R包,可以很容易地直接从R中构建交互式web应用程序。你可以在网页上托管独立的应用程序,也可以将它们嵌入其中R减价文件或构建指示板.你也可以扩展你的闪亮应用程序CSS的主题htmlwidgets,以及JavaScript行动
Shiny将R的计算能力与现代网络的交互性相结合。
这是一个闪亮的应用程序
出色的应用程序很容易编写。不需要web开发技能。

Shiny带有各种内置的输入小部件。使用最少的语法,可以在你的应用程序中包括像左边所示的小部件:
#选择要绘制的趋势类型selectInput(inputId = "type", label = strong(" trend index"), choices = unique(trend_data$type), selected = "Travel") #选择要绘制的日期范围dateRangeInput("date", strong(" date range"), start = "2007-01-01", end = "2017-07-31", min = "2007-01-01", max = "2017-07-31")
显示输出同样没有麻烦:
mainPanel(plotOutput(outputId = "lineplot", height = "300px"), textOutput(outputId = "desc"), tags$a(href = "https://www.google.com/finance/domestic_trends", "Source:谷歌国内趋势",target = "_blank"))
像你通常在R中那样构建你的图或表,并通过调用适当的渲染函数使它们具有反应性:
output$lineplot <- renderPlot({plot(x = selected_trends()$date, y = selected_trends()$close, type = "l", xlab = " date ", ylab = "Trend index")})
想知道我们是如何构建左侧显示的谷歌趋势指数应用程序的吗?请参阅下一个选项卡以获得完整的源代码。

#加载包库(shiny)库(shinythemes)库(dplyr)库(readr) #加载数据trend_data <- read_csv("data/trend_data.csv") trend_description <- read_csv("data/trend_description.csv") #定义UI UI <- fluidPage(theme = shinytheme("lumen"), titlePanel("谷歌趋势指数"),sidebarLayout(sidebarPanel(#选择趋势类型到plot selectInput(inputId = "type", label = strong("Trend Index"), choices = unique(trend_data$type), selected = "Travel"),#选择要绘制的日期范围dateRangeInput("date", strong(" date range"), start = "2007-01-01", end = "2017-07-31", min = "2007-01-01", max = "2017-07-31"), #选择是否覆盖平滑趋势线checkboxInput(inputId = "smooth ", label = strong(" overlay平滑趋势线"),value = FALSE), #选中平滑时才显示conditionalPanel(condition = "input. value ")。更平滑== true", sliderInput(inputId = "f", label = "更平滑的span:", min = 0.01, max = 1, value = 0.67, step = 0.01, animate = animationOptions(interval = 100)), HTML("越高的值越平滑。"))),#输出:描述,lineplot,和参考mainPanel(plotOutput(outputId = "lineplot", height = "300px"), textOutput(outputId = "desc"),标签$a(href = "https://www.google.com/finance/domestic_trends", "来源:谷歌国内趋势”,目标= "平等自愿 ") ) ) ) # 定义服务器功能服务器< -函数(输入、输出){#数据子集selected_trends < -活性({点播(输入日期)美元验证(需要(! is.na(输入日期[1]美元)& ! is.na(输入日期[2]美元),“错误:请提供一个开始和结束日期。”))验证(需要美元(输入日期[1]<输入日期[2],美元“错误:开始日期应早于结束日期。”)trend_data % > %过滤器(美元类型= =输入类型,日期> as.POSIXct(输入日期[1]美元)和日期<截止。POSIXct(输入日期[2美元 ] )) }) # 创建散点图对象plotOutput函数期望输出美元lineplot < - renderPlot({颜色= " # 434343 " par (mar = c(4 4 1 1)情节(x = selected_trends()美元日期,y = selected_trends()美元接近,类型=“l”,xlab =“日期”,ylab =“趋势指数”,上校=颜色,fg =颜色,col.lab =颜色,col.axis =颜色)#只显示如果顺畅的检查(输入平滑美元){smooth_curve < -洛斯(x = as.numeric (selected_trends()美元日期),y = selected_trends()美元接近,f = input$f) lines(smooth_curve, col = "#E6553A", lwd = 3)}}) # Pull in description of trend output$desc <- renderText({trend_text <- filter(trend_description, type == input$type) %>% Pull (text) paste(trend_text, "The index is set to 1.0 on January 1, 2004, and is计算only for US search traffic.")})} #创建Shiny对象shinyApp(ui = ui, server = server)
托管和部署

通过使用自己的服务器或Posit的托管服务,将你的Shiny应用放到网络上。

了解更多