[英]R Shiny App for Linear Regression, Issue with Render Functions
当我运行代码时,我没有收到任何错误,我的应用程序保持运行状态(由于代码错误,没有变成灰屏)。 但是,我在屏幕的左侧没有任何输出。 我假设我在某处有某种类型的语法错误,但我不太清楚。 这是我的代码,在您自己的R Studio上运行应该很容易。
这是我的用户界面:
shinyUI(fluidPage(
titlePanel("Linear Regression"),
sidebarLayout(position = "right",
mainPanel(h2("Your Model"), dataTableOutput("table")),
sidebarPanel(h2("Your Data"),
fileInput("mydata", label = h4("Please upload the .xls, .txt, or.csv file you would like included in the analysis. Please use column names in your dataset.")),
textInput("response", label=h4 ("What is the column name of your response variable?")),
textInput("explan1", label=h4 ("What is the column name of your explanitory variable?")),
actionButton("analysis", "Analyze!"),
verbatimTextOutput("modelSummary"),
plotOutput("plot")
)
)
)
)
这是我的服务器:
shinyServer({
function(input, output) ({
observeEvent(input$analysis, {
reactive({
dat <- file.path(input$mydata)
response=input$response
explan1=input$explan1
plot(input$response~input$explan1, data=dat)
mean.response<-mean(dat$response,na.rm=T)
abline(h=mean.Premium)
model=lm(response~explan1, data = dat)
output$plot <- renderPlot({
plot(input$response~input$explan1, data= dat)
abline(model,col="red")
})
output$modelSummary <- renderPrint({
summary(model)
})
})
})
})
})
对于renderText,我正在尝试使其输出整个摘要。 谢谢!
您从未分配过renderText
。 您的ui
也没有相应的textOutput
调用。 尽管您以闪亮的方式渲染对象,但必须将其作为输出给出。 但是, renderText
不适用于summary
返回的list
。 我将使用renderPrint
和verbatimTextOutput
提供输出。
另外,我不确定submitButton
。 我发现有更多控制与actionButton
和observeEvent
块。 个人喜好,但我似乎无法使submitButton
正常工作,因此这是我的解决方案。
这是一个极少可重复的示例,该示例演示如何使用您的布局以闪亮的方式显示summary
输出。 鉴于您没有提供可复制的数据集,我使用了mtcars
数据。
library(shiny)
data(mtcars)
runApp(
list(
ui = fluidPage(
titlePanel("Linear Regression"),
sidebarLayout(position = "right",
mainPanel(h2("Your Model"), dataTableOutput("table")),
sidebarPanel(h2("Your Data"),
fileInput("mydata", label = h4("Please upload the .xls, .txt, or.csv file you would like included in the analysis.")),
radioButtons("filetype", label = h4("Please select the type of data uploaded:"), c(".csv", ".txt", ".xls"), selected = ".xls"),
textInput("response", label=h4 ("What is the column name of your response variable?")),
textInput("explan1", label=h4 ("What is the column name of your explanitory variable?")),
actionButton("analysis","Analyze!"),
verbatimTextOutput("modelSummary")
)
)),
server = function(input, output) {
observeEvent( input$analysis, {
model=lm(mpg ~ hp, data = mtcars)
output$modelSummary <- renderPrint({
summary(model)
})
})
}
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.