【发布时间】:2016-12-31 04:33:12
【问题描述】:
我尝试构建一个闪亮的应用程序。目的是让用户在输入框中输入 csv 文件。然后用户可以在文本框中输入因变量名称。主面板将显示模型拟合和绘图的摘要详细信息。
我将以下代码编码为 ui.R:
library(shiny)
shinyUI(fluidPage(
titlePanel(h1("ANALYSIS",align = "center")),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Select CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
textInput("text", label = strong("Dependent Variable"),
value = "Enter Dependent Variable...")
),
mainPanel(br(),
textOutput('text1'),
plotOutput('plot')
)
)
))
以下作为 server.R :
library(shiny)
library(rpart)
library(rpart.plot)
shinyServer(function(input, output) {
output$text1 <- renderText({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
data <-read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote)
depVar <- input$text
modrpart <- rpart(depVar ~. ,data=data)
modrpart
#depVar
})
output$plot <- renderPlot({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
data <-read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote)
depVar <- input$text
modrpart <- rpart(depVar ~. ,data=data)
prp(modrpart)
})
})
当调用 RunApp 时,它显示错误“错误!:无效参数类型”。 模型详细信息和绘图未按预期显示在主面板中。我错过了一些东西。我使用https://drive.google.com/open?id=0B0ByEpXfdtGWMjZHUGpNc3ZZSTg 进行测试。谢谢
【问题讨论】:
-
你能把.csv上传到某个地方吗
-
谢谢@PorkChop。有一个输入框。您可以在 sidebarPanel 的输入框中选择任何可用的小 csv 文件。