【发布时间】: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 <- reactive({ req(input$amount) tibble(amount = seq(1, input$amount)) }) -
@PorkChop 这不起作用(没有错误消息,但没有任何渲染),并且不应该是必需的,
input$amount有一个声明的值。
标签: r shiny shiny-reactivity