[shiny 1]

作者: 一路向前_莫问前程_前程似锦 | 来源:发表于2020-07-02 09:27 被阅读0次

Shiny应用程序分为两个部分:用户界面定义和服务端脚本。

  1. 在教程的后续章节,我们将解释代码的细节并讲解如何用“反应性”表达式来生成输出。现在,就尝试运行一下例子程序,浏览一下源代码,以获得对shiny的初始印象。也请认真阅读注释。
library(shiny)

# Define UI for app that draws a histogram ----
ui <- fluidPage(

  # App title ----
  titlePanel("Hello Shiny!"),

  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    # Sidebar panel for inputs ----
    sidebarPanel(

      # Input: Slider for the number of bins ----
      sliderInput(inputId = "bins",
                  label = "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)

    ),

    # Main panel for displaying outputs ----
    mainPanel(

      # Output: Histogram ----
      plotOutput(outputId = "distPlot")

    )
  )
)

2.下面列出了服务端的代码。从某种程度上说,它很简单——生成给定个数的随机变量, 然后将直方图画出来。不过,你也注意到了,返回图形的函数被 renderPlot包裹着。函数上面的注释对此做出了一些解释,不过如果你觉得还是搞不明白,不用担心——后面我们将更进一步解释这个概念。

#定义绘制直方图所需的服务器逻辑
# Define server logic required to draw a histogram ----
server <- function(input, output) {

  # Histogram of the Old Faithful Geyser Data ----
  # with requested number of bins
  # This expression that generates a histogram is wrapped in a call
  # to renderPlot to indicate that:
  # 1. It is "reactive" and therefore should be automatically
  #    re-executed when inputs (input$bins) change 
它是“反应性的”,因此当输入(输入$bins)发生变化时应该是自动的 重新执行
  # 2. Its output type is a plot
  output$distPlot <- renderPlot({

    x    <- faithful$waiting
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    hist(x, breaks = bins, col = "#75AADB", border = "white",
         xlab = "Waiting time to next eruption (in mins)",
         main = "Histogram of waiting times")

    })

}

3.创建shinyapp

# Create Shiny app ----
shinyApp(ui = ui, server = server)

相关文章

  • LearningR-shiny

    1. shiny 1.1 About shiny 1.2 shiny examples 2. rsconnect ...

  • R语言:创建web界面

    1、shiny包 R语言使用shiny包创建web界面。使用shinydashboard包和shinytheme,...

  • [shiny 1]

    Shiny应用程序分为两个部分:用户界面定义和服务端脚本。 在教程的后续章节,我们将解释代码的细节并讲解如何用“反...

  • shiny部署

    有几种方式: 1. Shinyapps.io 2. Shiny server 3. Shiny Server Pr...

  • 「R shiny 基础」初识Shiny

    传送门 Shiny基础教程: 「R shiny 基础」初识Shiny 「R shiny 基础」如何进行网页布局 「...

  • Coding and Paper Letter(八十七)

    大家新年好,新一期资源整理博客。 1 Coding: 1.针对R语言新手的shiny培训教程。 shiny beg...

  • shiny学习(一)

    Shiny是一个R软件包,可很方便的从R直接构建交互式Web应用程序。 首先是安装Shiny软件包 Shiny有1...

  • Hello Shiny - 1

    写在前面:如果还没有安装shiny包,在一切开始之前请先安装shiny包。 一、先扔例子 这个例子是R自带的shi...

  • Shiny 教程1

    简介shiny 什么是shiny: Shiny 是一个开源的 R 包,它为使用 R 构建 Web 应用提供了一个优...

  • 【大数据部落】R语言用Shiny生态快速搭建交互网页应用

    原文链接:http://tecdat.cn/用shiny生态快速搭建交互网页应用/ 什么是Shiny? Shiny...

网友评论

      本文标题:[shiny 1]

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