【问题标题】:Scoping input in rshiny not found未找到 rshiny 中的范围输入
【发布时间】:2020-07-10 22:05:20
【问题描述】:

无法生成序列,因为input$amount 未生成,可能是由于我的文件夹结构。

错误信息:

考虑一个具有以下文件夹结构的 rshiny 应用程序:

.
├── app.R
├── _ui_elements
|   ├── body.R
|   ├── sidebar.R
|   └── _tabs
|       └── example_tab.R

其中代码如下:

app.R
library(shiny)
library(tidyverse)
library(shinydashboard)
library(plotly)

source("ui_elements/sidebar.R", local = TRUE)
source("ui_elements/body.R", local = TRUE)

ui <-
  dashboardPage(
    dashboardHeader(title = "Example"),
    sidebar,
    body
  )

server <- function(input, output, session) {

  amount_df <- reactive({
     tibble(amount = seq(1, input$amount))
  })

  output$amount_curve <- renderPlotly({

    amount_df() %>%
      ggplot(aes(amount)) +
        geom_point()

  })

}

shinyApp(ui = ui, server = server)

body.R
source("ui_elements/tabs/tab_example.R", local = TRUE)

body <-
  dashboardBody(
    tabItems(
      tab_example
      )
    )

sidebar.R
sidebar <-
  dashboardSidebar(
    sidebarMenu(
      menuItem("Example", tabName = "example", icon = icon("couch"))
      )
    )

tab_example.R
tab_example <-
tabItem(tabName = "example",
        fluidRow(
          column(6, numericInput("Amount","amount", min = 1, max = 1000, value = 500)),
          column(6, plotlyOutput("amount_curve"))
          )
        )

【问题讨论】:

  • amount_df &lt;- reactive({ req(input$amount) tibble(amount = seq(1, input$amount)) })
  • @PorkChop 这不起作用(没有错误消息,但没有任何渲染),并且不应该是必需的,input$amount 有一个声明的值。

标签: r shiny shiny-reactivity


【解决方案1】:

问题不在于文件结构,而在于参数的传递。您的参数inputIdlabel 的顺序错误。将tab_example.R中的代码改成如下。

tab_example <-
  tabItem(tabName = "example",
          fluidRow(
            column(6, numericInput(inputId = "amount",label = "Amount", min = 1, max = 1000, value = 500)),
            column(6, plotlyOutput("amount_curve"))
          )
  )

那时你会遇到新问题,但我认为你可以自己解决它们。

【讨论】:

    猜你喜欢
    • 2023-04-02
    • 2012-09-29
    • 1970-01-01
    • 2014-09-01
    • 2015-01-19
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    相关资源
    最近更新 更多