【发布时间】:2017-05-21 02:56:14
【问题描述】:
我正在尝试分离 Shiny 应用程序的功能以使其可重用。
我有我的 ui。我定义的 R 文件:
tabPanel("Unemployed", source("unemployed_select.R", local=TRUE)$value),
在我的 unused_select.R 我定义:
fluidPage(
titlePanel("Basic DataTable"),
# Create a new Row in the UI for selectInputs
fluidRow(
column(4,
selectInput("man",
"Manufacturer:",
c("All",
unique(as.character(mpg$manufacturer))))
),
column(4,
selectInput("trans",
"Transmission:",
c("All",
unique(as.character(mpg$trans))))
),
column(4,
selectInput("cyl",
"Cylinders:",
c("All",
unique(as.character(mpg$cyl))))
)
),
# Create a new row for the table.
fluidRow(
DT::dataTableOutput("table")
)
)
我的 server.R 文件是:
library(shiny)
library(shinythemes)
library(dataset)
shinyServer(function(input, output) {
# Filter data based on selections
output$table <- DT::renderDataTable(DT::datatable({
data <- mpg
if (input$man != "All") {
data <- data[data$manufacturer == input$man,]
}
if (input$cyl != "All") {
data <- data[data$cyl == input$cyl,]
}
if (input$trans != "All") {
data <- data[data$trans == input$trans,]
}
data
}))
})
我使用了 R 库 https://shiny.rstudio.com/gallery/basic-datatable.html 中一个著名示例中的代码
只是为了确保没有数据问题。仍然数据表没有呈现,所以我想它必须是定义内部源文件 unused_select.R 的问题。
有什么想法吗?
问候
【问题讨论】:
-
Do ỳou source
make_df.Rinserver.R? -
Yes Roman 使用 source("make_df.R")。我什至尝试在服务器文件夹中创建单独的脚本,试图遵循 showmeshiny 中的示例但没有成功
标签: r dataframe module shiny reactive