【发布时间】:2021-03-02 15:09:48
【问题描述】:
我正在学习开发闪亮的应用程序,我操作了一个在线示例来加载多个数据集,然后选择要可视化的数据集。代码如下:
# 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
library(shiny)
library(datasets)
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
# Return the requested dataset
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars,
"iris" = iris)
})
# 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)
})
})
您可能会注意到数据集、iris、mtcars 等是通过库数据集加载的。
问题:我有各种 .rds 文件,我想以与上述类似的方式加载和处理/可视化它们。但是,我不确定如何上传这些 .rds 文件并执行类似的任务,谁能帮我解决这个问题?
谢谢
【问题讨论】:
标签: r shiny shinydashboard shinyapps shiny-reactivity