シャイニーアプリケーションを再利用可能にするために、シャイニーアプリケーションの機能を分離しようとしています。シャイニーRアプリケーションコードのモジュール化
私は私は持っています。 R Iは、定義ファイル:
tabPanel("Unemployed", source("unemployed_select.R", local=TRUE)$value),
と私のunemployed_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
データの問題がないことを確認してください。まだデータレンダリングはレンダリングされていないので、ソースファイルを定義する際に問題がなければならないと思います。unemployed_select.R。
アイデア?
よろしく
'server.R'の' make_df.R'をソースしますか? –
はいローマ字( "make_df.R")を使用しています。私はサーバーフォルダ内に別のスクリプトを作成しようとしましたが、showmeshinyの例に従ってみましたが成功しませんでした – user1997567