R线性回归的闪亮应用程序,渲染函数问题

R线性回归的闪亮应用程序,渲染函数问题,r,output,shiny,render,R,Output,Shiny,Render,当我运行我的代码时,我没有收到任何错误,我的应用程序保持活跃(不会因为代码错误而变成灰色屏幕)。但是,我的屏幕左侧没有任何输出。我假设我在某处有某种语法错误,但我不能完全理解它。这是我的代码,应该很容易在自己的R Studio上运行 这是我的用户界面: shinyUI(fluidPage( titlePanel("Linear Regression"), sidebarLayout(position = "right", mainPanel(h2("Your Model"),

当我运行我的代码时,我没有收到任何错误,我的应用程序保持活跃(不会因为代码错误而变成灰色屏幕)。但是,我的屏幕左侧没有任何输出。我假设我在某处有某种语法错误,但我不能完全理解它。这是我的代码,应该很容易在自己的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)
        })
      })   
    })
  })
})
shinyServer({
功能(输入、输出)({
ObserveeEvent(输入$分析{
反应性({

dat您从未分配您的
renderText
。您的
ui
中也没有相应的
textOutput
调用。虽然您以闪亮的方式渲染对象,但它必须作为输出。但是,
renderText
对于从
摘要
返回的
列表
不起作用。我将d使用
renderPrint
逐字输出
提供输出

另外,我对
submitButton
不太确定。我发现
action按钮和
observeEvent
块有更多的控制。个人偏好,但我似乎无法让
submitButton
正常工作,所以我的解决方案如下

下面是一个可重复性最低的示例,演示如何使用您的布局将
摘要
输出打印为闪亮。鉴于您没有提供可重复的数据集,我使用了
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)
          })

      })
    }

))
库(闪亮)
数据(mtcars)
runApp(
名单(
ui=fluidPage(
titlePanel(“线性回归”),
侧边栏布局(position=“right”,
主面板(h2(“您的型号”)、dataTableOutput(“表格”),
侧边栏面板(h2(“您的数据”),
fileInput(“mydata”,label=h4(“请上传您希望包含在分析中的.xls、.txt或.csv文件”),
单选按钮(“文件类型”,标签=h4(“请选择上传的数据类型:”)、c(“csv”、“txt”、“.xls”)、selected=“.xls”),
textInput(“response”,label=h4(“您的响应变量的列名是什么?”),
textInput(“explan1”,label=h4(“您的解释变量的列名是什么?”),
操作按钮(“分析”,“分析!”),
逐字输出(“模型摘要”)
)
)),
服务器=功能(输入、输出){
ObserveeEvent(输入$分析{
型号=lm(mpg~hp,数据=mtcars)

output$modelSummary就我所知,您的应用程序运行正常。我可以看到应用程序左侧的所有菜单。如果您的意思是在单击“分析”后出现问题,您可能应该创建一个最小的可复制示例(即,不需要我们在应用程序中创建包含变量的文本文件)。我已经编辑了上面的代码以显示我现在拥有的内容。虽然我的控制台中没有出现错误或警告消息,但我仍然没有在我的应用程序中获得输出。@LindseyRegister删除
被动
语句。这不是必需的。我在尝试提交时删除了它并收到此错误消息:警告:观察者中未处理的错误:“character”observeEvent(input$analysis)类型的“envir”参数无效@LindseyRegister您可以运行我的代码而不出错吗?@LindseyRegister您使用的是什么闪亮版本?我的代码在
shinny_0.12.2
中运行而不出错。如果您完全复制了我的代码,您不应该收到该错误。