【问题标题】:Reactive app help in ShinyShiny 中的反应式应用程序帮助
【发布时间】:2018-04-30 19:12:57
【问题描述】:
library(shiny)
ui <- fluidPage(

# Application title
titlePanel("Linear model DARP"),
sidebarLayout(
sidebarPanel(
  selectInput('ycol', 'Select a resonse variable', names(df_ln)[c(12,13,14)],
              selected=names(df_ln)[[1]]),
  sliderInput(inputId = "area",
              "select the service region area(km^2):",
              min= 170,
              max= 8000,
              value=1001),
  sliderInput(inputId = "crit..peak",
              label="Choose Peak demand(Requests):",
              min=10,
              max=150,
              value=40),
  sliderInput(inputId ="Speed",
              label = "Please selct you average Speed(mph):",
              min=10,
              max=50,
              value = 15)
),


mainPanel(
  tableOutput("table"),
  h5('The data shows the fleetsize required for your selection of input variables')
   )
  )
)
 df_ln<-read.csv("F:/Project/Programme/ML/DAR Machine Learning TR Part 
 A/train_darp_ln.csv")
 server <- function(input, output) {

  output$table <- reactive({
renderTable({

Linearmodel_DARP<-lm(input$ycol~area+crit..peak+speed,data = df_ln)
new_demand<-data.frame(area=input$area,crit..peak=input$crit..peak,speed=input$Speed)

fleetsize<-predict(Linearmodel_DARP,newdata=new_demand)
round(exp(fleetsize),0)

    })
     })

         }

        # Run the application 
        shinyApp(ui = ui, server = server)

请帮助我反应性地应用线性模型并预测新的响应变量 从侧边栏中选择的 ycol 数据的预测应该显示在渲染表上并且在我的应用程序中我什么也没得到 我没有收到任何错误,但根据选择的预测数据未显示在应用程序中

dput(head(df_ln))
structure(list(area = c(2217.7, 6537.4, 1705.5, 5634, 1260.5, 
4797.7), density = c(0.13753, 0.016826, 0.18469, 0.021477, 0.25862, 
0.027305), crit..CV = c(0.63954, 0.81437, 0.49909, 0.33935, 0.39148, 
0.17489), crit..peak = c(49L, 26L, 41L, 20L, 39L, 18L), TW = c(21L, 
47L, 54L, 48L, 17L, 41L), L = c(569L, 576L, 391L, 390L, 458L, 
392L), s = c(7L, 3L, 3L, 6L, 3L, 2L), speed = c(18L, 26L, 20L, 
30L, 24L, 33L), circuity = c(1.3284, 1.1494, 1.4597, 1.2725, 
1.0486, 1.0792), cap = c(9L, 9L, 5L, 8L, 5L, 7L), mrt = c(1.5452, 
2.3743, 1.5962, 2.6065, 2.1278, 2.6228), veh = c(4.605170186, 
3.433987204, 4.718498871, 3.951243719, 4.060443011, 3.526360525
), veh.hrs = c(6.665569062, 5.523778231, 6.496186582, 5.71857256, 
5.816843267, 5.256713817), veh.km = c(9.555940819, 8.781874769, 
9.491918855, 9.119769942, 8.994897097, 8.753221378)), row.names = c(NA, 
6L), class = "data.frame")

【问题讨论】:

  • 请提供dput(df_ln) 的输出,以便我们尝试使用您的数据。或者 dput(head(df_ln)) 如果够用的话。
  • 添加了 dput(head(df_ln))

标签: r shiny


【解决方案1】:

至少有两个错误:

  • output$table &lt;- reactive({renderTable...... -> 删除reactive

  • lm(input$ycol~.....中,input$ycol是一个字符串,不能工作;替换为lm(df_ln[[input$ycol]] ~ ....

做了这两个修改后,我得到了以下应用程序。是你想要的吗?

【讨论】:

  • 谢谢我得到了输出
  • 您能检查一下我们如何更改输出名称而不是闪亮界面中显示的数据吗?我的意思是我们可以在输出中写其他东西而不是数据。怎么做?
猜你喜欢
  • 2019-12-02
  • 1970-01-01
  • 2011-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多