mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
commit
e3132fbedb
@ -1,164 +0,0 @@
|
||||
[#]: subject: "Using R for Building an Interactive Web App"
|
||||
[#]: via: "https://www.opensourceforu.com/2022/10/using-r-for-building-an-interactive-web-app/"
|
||||
[#]: author: "Dr Kumar Gaurav https://www.opensourceforu.com/author/dr-gaurav-kumar/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "charonxin "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Using R for Building an Interactive Web App
|
||||
======
|
||||
*Data analysis has become imperative for companies, and there is a huge demand for data-driven applications with user friendly interfaces. This article tells you how to develop an interactive web app using the Shiny package in R, which is a popular programming language for data science.*
|
||||
|
||||
Nearly every business across the world relies on data today, in some way or the other. In fact, data science has helped transform many businesses by using data-driven applications, whether in the field of finance, banking, retail, logistics, e-commerce, transportation, airlines, or any other.
|
||||
|
||||
High performance computers and low-cost storage allow us to predict results in minutes today rather than the many hours it used to take earlier. Data scientists focused on the future are developing easy to use applications with high performance and multi-dimensional visualisation. It all starts with Big Data, which consists of three components: quantity, diversity, and velocity. Algorithms and models are fed from this data. The most cutting-edge data scientists working in machine learning and AI are creating models that self-improve, detecting and learning from their errors.
|
||||
|
||||
Statistics and computing are used to turn data into useful information in the field of data science, often termed as data-driven science. Data science is a synthesis of methods from a variety of fields to gather, analyse, and interpret data in order to develop new insights and make choices. The technological disciplines that constitute data science include statistics, probability, mathematics, machine learning, business intelligence, and some programming.
|
||||
Data science can be applied in various areas (Figure 1). The analysis of large, complicated data sets is the focus of data science. It has helped to create a new universe in which data is seen in whole new ways. Tech giants like Amazon, Google, and Facebook use data science principles for business intelligence and decision making.
|
||||
|
||||
![Figure 1 Key applications-and use cases of data science][1]
|
||||
|
||||
### R: The language for data science
|
||||
|
||||
Data analysis and insights are urgently needed because of the volume of information available. Raw data is transformed into finished data products with the help of a number of technologies. When it comes to research, processing, transformation, and visualisation of data, there are few better tools than R.
|
||||
|
||||
The key features in R for data science are:
|
||||
|
||||
* Data pre-processing
|
||||
* Social media fetching and analysis
|
||||
* Assorted operations on data frames
|
||||
* Extract, transform, load (ETL)
|
||||
* Connection to a variety of databases, including SQL and spreadsheets
|
||||
* Interaction with NoSQL databases
|
||||
* Training and prediction with models
|
||||
* Machine learning models
|
||||
* Clustering
|
||||
* Fourier transform
|
||||
* Web scraping
|
||||
|
||||
R is a robust programming language commonly used in statistical computation and data analysis. Efforts to enhance R’s user interface have been going on since long. Several data science groups throughout the world have followed the development of R from a simple text editor to the more current interactive R Studio and Jupyter Notebooks.
|
||||
|
||||
Only the contributions of R users throughout the world have made this possible. The inclusion of strong packages in R has made it increasingly powerful over time. Numerous open source packages have made it easier and more efficient to work with large data sets and visualise data.
|
||||
|
||||
### Developing interactive web applications in R using Shiny
|
||||
|
||||
You can construct interactive web apps in R using the Shiny package. Apps can be hosted on a website, embedded in R Markdown documents, or used to develop dashboards and visualisations. CSS themes, HTML widgets, and JavaScript actions can all be used to customise your Shiny apps further.
|
||||
|
||||
Shiny is an R tool that makes it simple to create interactive web apps. It allows you to extend your R code to the web so that it may benefit from the larger community of people who can use it.
|
||||
|
||||
In addition to Shiny’s built-in features, there are a number of third-party extension packages available, such as shinythemes, shinydashboard, and shinyjs.
|
||||
|
||||
There are various apps that can be developed using Shiny. Here is a list of a few of them.
|
||||
|
||||
* Machine learning based web apps
|
||||
* Web apps with dynamic controls
|
||||
* Data-driven dashboards
|
||||
* Interactive apps for multiple data sets
|
||||
* Real-time data visualisation panels
|
||||
* Data collection forms
|
||||
* Shiny web apps can be divided into the following:
|
||||
* User interface
|
||||
* Server function
|
||||
* Shiny app function
|
||||
|
||||
For better understanding, you can refer to the examples and use cases available at https://shiny.rstudio.com/gallery/.
|
||||
|
||||
One of the apps developed using Shiny is shown in Figure 2 (https://shiny.rstudio.com/gallery/radiant.html).
|
||||
|
||||
![Figure 2: Shiny based app][2]
|
||||
|
||||
### Generation of a sales dashboard
|
||||
|
||||
The code snippet for a web app related to a sales dashboard is given below. This dashboard has multiple controls and user interface modules to view the data.
|
||||
|
||||
First, the Shiny package is installed and then it is called in the code so that the output can be presented in the form of a web page.
|
||||
|
||||
```
|
||||
library(shiny)
|
||||
library(dplyr)
|
||||
|
||||
sales <- vroom::vroom(“salesdata.csv”, na = “”)
|
||||
ui <- fluidPage(
|
||||
titlePanel(“Dashboard for Sales Data”),
|
||||
sidebarLayout(
|
||||
sidebarPanel(
|
||||
selectInput(“territories”, “territories”, choices = unique(sales$territories)),
|
||||
selectInput(“Customers”, “Customer”, choices = NULL),
|
||||
selectInput(“orders”, “Order number”, choices = NULL, size = 5, selectize = FALSE),
|
||||
),
|
||||
mainPanel(
|
||||
uiOutput(“customer”),
|
||||
tableOutput(“data”)
|
||||
)
|
||||
)
|
||||
)
|
||||
server <- function(input, output, session) {
|
||||
territories <- reactive({
|
||||
req(input$territories)
|
||||
filter(sales, territories == input$territories)
|
||||
})
|
||||
customer <- reactive({
|
||||
req(input$Customers)
|
||||
filter(territories(), Customers == input$Customers)
|
||||
})
|
||||
|
||||
output$customer <- renderUI({
|
||||
row <- customer()[1, ]
|
||||
tags$div(
|
||||
class = “well”,
|
||||
tags$p(tags$strong(“Name: “), row$customers),
|
||||
tags$p(tags$strong(“Phone: “), row$contact),
|
||||
tags$p(tags$strong(“Contact: “), row$fname, “ “, row$lname)
|
||||
)
|
||||
})
|
||||
|
||||
order <- reactive({
|
||||
req(input$order)
|
||||
customer() %>%
|
||||
filter(ORDER == input$order) %>%
|
||||
arrange(OLNUMBER) %>%
|
||||
select(pline, qty, price, sales, status)
|
||||
})
|
||||
|
||||
output$data <- renderTable(order())
|
||||
|
||||
observeEvent(territories(), {
|
||||
updateSelectInput(session, “Customers”, choices = unique(territories()$Customers), selected = character())
|
||||
})
|
||||
observeEvent(customer(), {
|
||||
updateSelectInput(session, “order”, choices = unique(customer()$order))
|
||||
})
|
||||
}
|
||||
shinyApp(ui, server)
|
||||
```
|
||||
|
||||
On running the code of the Shiny app, the output shown in Figure 3 is generated which can be viewed on any web browser. The sales dashboard has multiple controls and is quite interactive with different user interface modules.
|
||||
|
||||
![Figure 3: Sales dashboard with multiple controls][3]
|
||||
|
||||
With the use of Shiny cloud, this app can be deployed and hosted on the cloud for anytime anywhere availability on the internet.
|
||||
|
||||
![Figure 4: Cloud for hosting and deployment of Shiny app][4]
|
||||
|
||||
The free variant of Shiny cloud allows five applications to be deployed within 25 active hours.
|
||||
Researchers and data scientists can develop user-friendly apps driven with real-time data using the Shiny library of R. This library can also be used for deploying their machine learning apps on web platforms.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.opensourceforu.com/2022/10/using-r-for-building-an-interactive-web-app/
|
||||
|
||||
作者:[Dr Kumar Gaurav][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/Charonxin)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.opensourceforu.com/author/dr-gaurav-kumar/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/09/Figure-1-Key-applications-and-use-cases-of-data-science.jpg
|
||||
[2]: https://www.opensourceforu.com/wp-content/uploads/2022/09/Figure-2-Shiny-based-app.jpg
|
||||
[3]: https://www.opensourceforu.com/wp-content/uploads/2022/09/Figure-3-Sales-dashboard-with-multiple-controls.jpg
|
||||
[4]: https://www.opensourceforu.com/wp-content/uploads/2022/09/Figure-4-Cloud-for-hosting-and-deployment-of-Shiny-app.jpg
|
@ -0,0 +1,171 @@
|
||||
[#]: subject: "Using R for Building an Interactive Web App"
|
||||
[#]: via: "https://www.opensourceforu.com/2022/10/using-r-for-building-an-interactive-web-app/"
|
||||
[#]: author: "Dr Kumar Gaurav https://www.opensourceforu.com/author/dr-gaurav-kumar/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "charonxin "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
使用 R 语言构建一个可交互的 Web 应用
|
||||
======
|
||||
*数据分析已成为企业的当务之急,并且对具有用户友好界面的数据驱动应用程序有巨大的需求。本文介绍如何使用 R 语言中的 Shiny 包开发交互式 Web 应用程序,R 语言是一种流行的数据科学编程语言。*
|
||||
|
||||
如今,世界各地几乎所有企业都以某种形式依赖于数据。数据科学通过使用数据驱动的应用程序帮助许多企业实现转型,无论是在金融、银行、零售、物流、电子商务、运输、航空还是任何其他领域。
|
||||
|
||||
高性能计算机和低成本存储使我们现在能够在几分钟内预测结果,而不是像以前一样以前需要花费很多时间。数据科学家着眼于未来,正在开发具有高性能和多维可视化的便捷应用。这一切都始于大数据,它由三个组成部分组成:数量、多样性和速度。算法和模型都是根据这些数据提供的。机器学习和人工智能领域最前沿的数据科学家正在创建能够自我改进、检测错误并从中学习的模型。
|
||||
|
||||
|
||||
在数据科学领域,统计和计算用于将数据转化为有用的信息,通常称为数据驱动科学。数据科学是来自各个领域的方法的综合,用于收集、分析和解释数据,以形成新的见解并做出选择。构成数据科学的技术学科包括统计学、概率、数学、机器学习、商业智能和一些编程。
|
||||
|
||||
|
||||
数据科学可以应用于各个领域(图1)。对大型、复杂数据集的分析是数据科学的重点。它帮助我们创建了一个以全新方式看待数据的新宇宙。亚马逊、谷歌和 Facebook 等科技巨头利用数据科学原理进行商业智能和商业决策。
|
||||
|
||||
|
||||
![Figure 1 Key applications-and use cases of data science][1]
|
||||
|
||||
### R: 为数据科学量身打造的语言
|
||||
|
||||
由于巨量的可用信息迫切需要数据分析以得到新的见解,在多种技术的帮助下,原始数据转化为成品数据产品。在数据研究、处理、转换和可视化方面,没有比 R 语言更好的工具了。
|
||||
|
||||
R 语言用于数据科学的主要功能包括:
|
||||
|
||||
* 数据预处理
|
||||
* 社交媒体数据获取和分析
|
||||
* 对数据结构的各种操作
|
||||
* 提取、转换、加载(ETL)
|
||||
* 连接到各种数据库,包括 SQL 和电子表格
|
||||
* 与 NoSQL 数据库交互
|
||||
* 使用模型进行训练和预测
|
||||
* 机器学习模型
|
||||
* 聚类
|
||||
* 傅里叶变换
|
||||
* 网页抓取
|
||||
|
||||
R 语言是一种强大的编程语言,常用于统计计算和数据分析。有关优化 R 语言用户界面的努力由来已久。世界各地的多个数据科学小组都在关注 R 从简单的文本编辑器到更现代的交互式 R Studio 和 Jupyter Notebooks 的发展。
|
||||
|
||||
只有全世界 R 用户的贡献才使这一切成为可能。 R 语言中包含的强大软件包使其日益强大。许多开源软件包使处理大型数据集和可视化数据变得更加容易和高效。
|
||||
|
||||
|
||||
### 使用 Shiny 在 R 语言中开发交互式 Web 应用
|
||||
|
||||
|
||||
您可以使用 Shiny 包在 R 中构建交互式 Web 应用程序。应用程序可以托管在网站上、嵌入 R Markdown 文档中或用于开发控制面板板和可视化。 CSS 主题、HTML 小部件和 JavaScript 操作都可以用于进一步自定义您的 Shiny 应用程序。
|
||||
|
||||
|
||||
Shiny 是一款R语言工具,它可以轻松创建交互式的 Web 应用程序。它允许你将你的 R 代码扩展到 Web 上,从而使更多的人能够使用它,从中获益。
|
||||
|
||||
除了 Shiny 内置的功能外,还有许多第三方扩展包可用,例如 shinythemes、shinydashboard 和 shinyjs。
|
||||
|
||||
使用Shiny可以开发各种应用程序。以下是其中一些的列表:
|
||||
|
||||
* 基于 web 应用的机器学习
|
||||
* 具有动态控件的 Web 应用程序
|
||||
* 数据驱动的仪表盘
|
||||
* 多重数据集的交互式应用
|
||||
* 实时数据可视化面板
|
||||
* 数据收集表单
|
||||
* Shiny web 应用程序可以分为以下几类:
|
||||
* 用户接口
|
||||
* 服务功能逻辑
|
||||
* Shiny 应用逻辑
|
||||
|
||||
|
||||
获取更深理解,请访问以下网站 https://shiny.rstudio.com/gallery/.
|
||||
|
||||
其中某个用 Shiny 开发的应用如图2 (https://shiny.rstudio.com/gallery/radiant.html).
|
||||
|
||||
![Figure 2: Shiny based app][2]
|
||||
|
||||
### 销售仪表盘的生成
|
||||
|
||||
下面是一个与销售仪表盘相关的 Web 应用程序的代码片段。该仪表板具有多个控件和用户界面模块,用于查看数据。
|
||||
|
||||
首先,安装 Shiny 包,然后在代码中调用它,以便将输出呈现为 Web 页面的形式。
|
||||
|
||||
```
|
||||
library(shiny)
|
||||
library(dplyr)
|
||||
|
||||
sales <- vroom::vroom(“salesdata.csv”, na = “”)
|
||||
ui <- fluidPage(
|
||||
titlePanel(“Dashboard for Sales Data”),
|
||||
sidebarLayout(
|
||||
sidebarPanel(
|
||||
selectInput(“territories”, “territories”, choices = unique(sales$territories)),
|
||||
selectInput(“Customers”, “Customer”, choices = NULL),
|
||||
selectInput(“orders”, “Order number”, choices = NULL, size = 5, selectize = FALSE),
|
||||
),
|
||||
mainPanel(
|
||||
uiOutput(“customer”),
|
||||
tableOutput(“data”)
|
||||
)
|
||||
)
|
||||
)
|
||||
server <- function(input, output, session) {
|
||||
territories <- reactive({
|
||||
req(input$territories)
|
||||
filter(sales, territories == input$territories)
|
||||
})
|
||||
customer <- reactive({
|
||||
req(input$Customers)
|
||||
filter(territories(), Customers == input$Customers)
|
||||
})
|
||||
|
||||
output$customer <- renderUI({
|
||||
row <- customer()[1, ]
|
||||
tags$div(
|
||||
class = “well”,
|
||||
tags$p(tags$strong(“Name: “), row$customers),
|
||||
tags$p(tags$strong(“Phone: “), row$contact),
|
||||
tags$p(tags$strong(“Contact: “), row$fname, “ “, row$lname)
|
||||
)
|
||||
})
|
||||
|
||||
order <- reactive({
|
||||
req(input$order)
|
||||
customer() %>%
|
||||
filter(ORDER == input$order) %>%
|
||||
arrange(OLNUMBER) %>%
|
||||
select(pline, qty, price, sales, status)
|
||||
})
|
||||
|
||||
output$data <- renderTable(order())
|
||||
|
||||
observeEvent(territories(), {
|
||||
updateSelectInput(session, “Customers”, choices = unique(territories()$Customers), selected = character())
|
||||
})
|
||||
observeEvent(customer(), {
|
||||
updateSelectInput(session, “order”, choices = unique(customer()$order))
|
||||
})
|
||||
}
|
||||
shinyApp(ui, server)
|
||||
```
|
||||
|
||||
运行 Shiny 应用程序的代码后,生成了图3所示的输出,可以在任何 Web 浏览器上查看。销售仪表盘具有多个控件,并且具有不同的用户界面模块,非常互动。
|
||||
|
||||
![Figure 3: Sales dashboard with multiple controls][3]
|
||||
|
||||
通过使用 Shiny Cloud,可以将这个应用程序部署和托管在云上,以便随时随地在互联网上使用。
|
||||
|
||||
![Figure 4: Cloud for hosting and deployment of Shiny app][4]
|
||||
|
||||
Shiny Cloud 的免费版本允许在25个活动小时内部署五个应用程序。研究人员和数据科学家可以使用R的Shiny 库开发基于实时数据驱动的用户友好应用程序。这个库也可以用于在 Web 平台上部署他们的机器学习应用程序。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.opensourceforu.com/2022/10/using-r-for-building-an-interactive-web-app/
|
||||
|
||||
作者:[Dr Kumar Gaurav][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/Charonxin)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.opensourceforu.com/author/dr-gaurav-kumar/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.opensourceforu.com/wp-content/uploads/2022/09/Figure-1-Key-applications-and-use-cases-of-data-science.jpg
|
||||
[2]: https://www.opensourceforu.com/wp-content/uploads/2022/09/Figure-2-Shiny-based-app.jpg
|
||||
[3]: https://www.opensourceforu.com/wp-content/uploads/2022/09/Figure-3-Sales-dashboard-with-multiple-controls.jpg
|
||||
[4]: https://www.opensourceforu.com/wp-content/uploads/2022/09/Figure-4-Cloud-for-hosting-and-deployment-of-Shiny-app.jpg
|
Loading…
Reference in New Issue
Block a user