Rshiny中的数据集

Rshiny中的数据集,shiny,shinydashboard,shinyapps,shiny-reactivity,Shiny,Shinydashboard,Shinyapps,Shiny Reactivity,我正在学习开发闪亮的应用程序,我操作了一个在线示例来加载多个数据集,然后选择要可视化的数据集。代码如下: # ui.R library(shiny) library(shinythemes) # Define UI for dataset viewer application shinyUI(fluidPage(theme = shinytheme("cerulean"), pageWithSidebar( # Application title

我正在学习开发闪亮的应用程序,我操作了一个在线示例来加载多个数据集,然后选择要可视化的数据集。代码如下:

# ui.R

library(shiny)
library(shinythemes)
# Define UI for dataset viewer application
shinyUI(fluidPage(theme = shinytheme("cerulean"), pageWithSidebar(
    
    # Application title
    headerPanel("Shiny App with multiple datasets"),
    # Sidebar with controls to select a dataset and specify the number
    # of observations to view
    sidebarPanel(
        selectInput("dataset", "Choose a dataset:", 
                    choices = c("rock", "pressure", "cars","iris")),
        
        numericInput("obs", "Number of observations to view:",100)
    ),
    
    # Show a summary of the dataset and an HTML table with the requested
    # number of observations
    mainPanel(
        tabsetPanel(
            tabPanel('Summary Stats', verbatimTextOutput("summary")),
            tabPanel('Table', DT::DTOutput("view"))
            
        ))
        
)))

#server.R
图书馆(闪亮)
图书馆(数据集)
#定义汇总和查看所选数据集所需的服务器逻辑
shinyServer(功能(输入、输出){
#返回请求的数据集

datasetInput我过去曾将rds文件存储在应用程序目录中的特定目录中,并将这些文件读取到应用程序中

library(shiny)
library(shinythemes)
library(datasets)

# saved some date as rds files to test app

iris <- iris
saveRDS(iris, "./data/iris.rds")
mtcars <- mtcars
saveRDS(mtcars, "./data/mtcars.rds")

# Getting the file names
rdsfiles <- list.files("./data", pattern = "\\.rds$")

# Define UI for dataset viewer application
ui <- shinyUI(fluidPage(theme = shinytheme("cerulean"), pageWithSidebar(

 # Application title
 headerPanel("Shiny App with multiple datasets"),
 # Sidebar with controls to select a dataset and specify the number
 # of observations to view
 sidebarPanel(
   selectInput("dataset", "Choose a dataset:", 
               choices = rdsfiles),

   numericInput("obs", "Number of observations to view:",100)
   ),

   # Show a summary of the dataset and an HTML table with the requested
   # number of observations
   mainPanel(
    tabsetPanel(
    tabPanel('Summary Stats', verbatimTextOutput("summary")),
    tabPanel('Table', DT::DTOutput("view"))
  
  ))

)))


# Define server logic required to summarize and view the selected dataset
server <- shinyServer(function(input, output) {

# Return the requested dataset
datasetInput <- reactive({
   df <- readRDS(paste0("./data/", input$dataset))
   return(df)
})

 # Generate a summary of the dataset
 output$summary <- renderPrint({
  dataset <- datasetInput()
  summary(dataset)
 })

 # Show the first "n" observations
 output$view <- DT::renderDT({
   head(datasetInput(), n = input$obs)
 })

})


shinyApp(ui, server)
库(闪亮)
图书馆(shinythemes)
图书馆(数据集)
#将某些日期保存为rds文件以测试应用程序

iris我过去曾将rds文件存储在应用程序目录中的特定目录中,并将这些文件读取到应用程序中

library(shiny)
library(shinythemes)
library(datasets)

# saved some date as rds files to test app

iris <- iris
saveRDS(iris, "./data/iris.rds")
mtcars <- mtcars
saveRDS(mtcars, "./data/mtcars.rds")

# Getting the file names
rdsfiles <- list.files("./data", pattern = "\\.rds$")

# Define UI for dataset viewer application
ui <- shinyUI(fluidPage(theme = shinytheme("cerulean"), pageWithSidebar(

 # Application title
 headerPanel("Shiny App with multiple datasets"),
 # Sidebar with controls to select a dataset and specify the number
 # of observations to view
 sidebarPanel(
   selectInput("dataset", "Choose a dataset:", 
               choices = rdsfiles),

   numericInput("obs", "Number of observations to view:",100)
   ),

   # Show a summary of the dataset and an HTML table with the requested
   # number of observations
   mainPanel(
    tabsetPanel(
    tabPanel('Summary Stats', verbatimTextOutput("summary")),
    tabPanel('Table', DT::DTOutput("view"))
  
  ))

)))


# Define server logic required to summarize and view the selected dataset
server <- shinyServer(function(input, output) {

# Return the requested dataset
datasetInput <- reactive({
   df <- readRDS(paste0("./data/", input$dataset))
   return(df)
})

 # Generate a summary of the dataset
 output$summary <- renderPrint({
  dataset <- datasetInput()
  summary(dataset)
 })

 # Show the first "n" observations
 output$view <- DT::renderDT({
   head(datasetInput(), n = input$obs)
 })

})


shinyApp(ui, server)
库(闪亮)
图书馆(shinythemes)
图书馆(数据集)
#将某些日期保存为rds文件以测试应用程序
虹膜