【问题标题】:Shiny - Input Argument Not AccessibleShiny - 输入参数不可访问
【发布时间】:2018-03-19 06:00:06
【问题描述】:

我正在尝试从闪亮的滑块中获取输入,并通过调用其上的函数来在服务器部分中使用它来获取图形信息。但是,来自滑块的输入在服务器端无法识别,并引发错误。

评估错误:缺少参数“小时”,没有默认值。

inputID 与参数匹配,所以我不明白为什么它无法访问它。

library(shiny)
library(shinydashboard)
get_data <- function(foo){return(foo)}

#build shiny app
header <- dashboardHeader(
            title="Data"
          )
sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Charts and Analysis", tabName = "charts", icon = icon("bar-chart-o"), 
             menuSubItem("Temperature by Time of Day", tabName = "temperatures", icon = NULL)        )        
  )
)

body <- dashboardBody(
  tabItems(
    tabItem(tabName = "temperatures",
      fluidRow(
        box(
            title = "Time of Day",
            sliderInput(inputId = "hour", label="Hour (military)", min=0, max=23, value=12, step=1)
        ),
        box(plotOutput("series"))
      )
    )


  )


)


ui <- dashboardPage(skin="green", header, sidebar, body)
server <- function(input, output) { 

  MR <- get_data(strtoi(input$hour))
  output$series <- renderPlot({
    plot(x=MR, y=MR) 
   })
}

shinyApp(ui, server)

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    在闪亮的应用程序中,对输入参数的调用必须在反应式上下文中。 然后我们必须将函数赋值移到renderPlot函数中。

    library(shiny)
    library(shinydashboard)
    get_data <- function(foo){return(foo)}
    
    #build shiny app
    header <- dashboardHeader(
                title="Data"
              )
    sidebar <- dashboardSidebar(
      sidebarMenu(
        menuItem("Charts and Analysis", tabName = "charts", icon = icon("bar-chart-o"), 
                 menuSubItem("Temperature by Time of Day", tabName = "temperatures", icon = NULL)        )        
      )
    )
    
    body <- dashboardBody(
      tabItems(
        tabItem(tabName = "temperatures",
          fluidRow(
            box(
                title = "Time of Day",
                sliderInput(inputId = "hour", label="Hour (military)", min=0, max=23, value=12, step=1)
            ),
            box(plotOutput("series"))
          )
        )
    
    
      )
    
    
    )
    
    
    ui <- dashboardPage(skin="green", header, sidebar, body)
    server <- function(input, output) { 
    
    
      output$series <- renderPlot({
        MR <- get_data(strtoi(input$hour))
        plot(x=MR, y=MR) 
       })
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多