试图建立我的第一个闪亮的应用程序

时间:2016-11-07 17:04:46

标签: r shiny

我在这里看到了视频教程。

http://blog.revolutionanalytics.com/2016/03/rtvs-preview.html

在24:15左右,教练开始谈论他建立的闪亮应用程序。他预先构建了它,并且只是运行它,所以我基本上不可能弄清楚他是如何从无到有而真正的应用程序。我在YouTube上观看了一些教程,它们对帮助我提高速度有所帮助,但仍然无法实现这一目标。尽我所知,这些是(某种程度的)步骤,但同样,我仍然无法实现这一目标。

RStudio>文件>新文件>闪亮的Web应用程序。然后命名应用程序并创建一个目录。

现在,我有一个看起来像这样的模板。

#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)

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

   # Application title
   titlePanel("Old Faithful Geyser Data"),

   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)
      ),

      # Show a plot of the generated distribution
      mainPanel(
         plotOutput("distPlot")
      )
   )
))

# Define server logic required to draw a histogram
server <- shinyServer(function(input, output) {

   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2] 
      bins <- seq(min(x), max(x), length.out = input$bins + 1)

      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
})

# Run the application 
shinyApp(ui = ui, server = server)

根据视频,我创建了一个模板(带有一些基本的R代码)。它看起来像这样。

library(shiny)
library(leaflet)
library(plyr)


ui <- fluidPage(
  actionButton("recalc", "New points"),
  mainPanel(
    tabsetPanel(
      tabPanel("Order Locations", leafletOutput("map",width="80%",height="400px")),
      tabPanel("Markers", verbatimTextOutput("markers"))
    )
  )
)


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

  airports <- read.csv("https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat", header = FALSE)
  colnames(airports) <- c("ID", "name", "city", "country", "IATA_FAA", "ICAO", "lat", "lon", "altitude", "timezone", "DST")
  countries <- sort(unlist(lapply(unique(airports$country), as.character)))

}

shinyApp(ui, server)

这根本不做任何事情。啊。

我相信&#39; ui&#39;是一个从&#39;服务器调用参数的函数。是对的吗?我是靠近还是离开基地?我怎样才能使这个工作?看起来非常有用。我试图学习这些东西的细节,所以我可以自己做。谢谢!

0 个答案:

没有答案