【发布时间】:2015-03-23 02:03:44
【问题描述】:
提前感谢您的帮助。我了解如何根据预定义数据集的其他输入来操作动态输入。 即加载汽车数据集。用户选择单选按钮表示他们只想查看蓝色汽车。这会更改 UI 上某些输入选择器中的选项。
但是,如果我想允许用户上传 csv 文件,我该如何动态更新所有相关的小部件。 即用户上传他们的数据,输入选择器显示数据集中的所有变量用于绘图和回归。
斜体部分是我的麻烦。
ui.r
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
titlePanel("My R Shiny App"),
sidebarPanel(
fileInput('file', 'Choose file to upload.'),
#Select Box: y
selectInput("y_input", label = h5("Select Time Series/Response Variable"),
choices = names(myData),
selected = NULL)
)
)
)
server.r
library(shiny)
#Run once when app is launched
#Load data
shinyServer(function(input, output) {
#Run once each time a user visits the app
#Put code to build a distinct set of reactive objects for user
output$Variable_Selector <- renderUI({
if(is.null(input$file))
return(NULL)
inFile <- input$file
myData <- read.csv(inFile$datapath)
if (is.null(myData))
return(NULL)
})
})
global.r
myData = NULL
谢谢!
【问题讨论】:
标签: r shiny shiny-server