光沢のあるアプリをモジュール化する:CSVおよびチャートモジュール

MayaGans

モジュール化されたShinyアプリを作成したいのですが、1つのモジュールdataUploadがCSVのインポートに使用され、別のモジュールchartが次の目的で使用されます。

  1. CSV内の列名に基づいて動的なxおよびyドロップダウンを作成するこの作品
  2. 選択したinput $ xaxis、input $ yaxisに基づいてプロットを作成します。これにより、ベクトル割り当てで無効なタイプ/長さ(シンボル/ 0)のエラーが生成されます。

問題はchart.Rのリアクティブggplotにあると思います。助けが必要です。ここにすべての情報を追加しましたが、それが簡単な場合はgithubリポジトリもあります。これはの世界への本当に素晴らしいデモになると思います。相互作用するモジュールなので、助けていただければ幸いです。

App.R

library(shiny)
library(shinyjs)
library(tidyverse)

source("global.R")

ui <- 
  tagList(
    navbarPage(
      "TWO MODULES",
      tabPanel(
        title = "Data",
          dataUploadUI("datafile", "Import CSV")
      ),
      tabPanel(
        title = "Charts",
          chartUI("my_chart")
      )
    )
  )

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

  datafile <- callModule(dataUpload, "datafile", stringsAsFactors = FALSE)
  output$table <- renderTable({ datafile() })

  # PASS datafile WITHOUT () INTO THE MODULE 
  my_chart <- callModule(chart, "my_chart", datafile = datafile)
  output$plot <- renderPlot({ my_chart() })

}

shinyApp(ui, server)

dataUpload.R

dataUpload <- function(input, output, session, stringsAsFactors) {
  # The selected file, if any
  userFile <- reactive({
    # If no file is selected, don't do anything
    # input$file == ns("file")
    validate(need(input$file, message = FALSE))
    input$file
  })

  # The user's data, parsed into a data frame
  dataframe <- reactive({
    read.csv(userFile()$datapath,
             stringsAsFactors = stringsAsFactors)
  })

  # We can run observers in here if we want to
  observe({
    msg <- sprintf("File %s was uploaded", userFile()$name)
    cat(msg, "\n")
  })

  # Return the reactive that yields the data frame
  return(dataframe)

}

dataUploadUI.R

# The first argument is the id -- the namespace for the module
dataUploadUI <- function(id, label = "CSV file") {
  # Create a namespace function using the provided id
  #ALL UI FUNCTION BODIES MUST BEGIN WITH THIS
  ns <- NS(id)
  # Rather than fluidPage use a taglist
  # If you're just returning a div you can skip the taglist
  tagList(
  sidebarPanel(
    fileInput(ns("file"), label)),

  mainPanel(tableOutput("table"))
  )
}

chart.R

これは、プロットを適切にレンダリングするために若干の変更が必要なファイルだと思いますか?

chart <- function(input, output, session, datafile = reactive(NULL)) {

  # SINCE DATAFILE IS A REACTIVE WE ADD THE PRERENTHESIS HERE
  # WHERE/HOW CAN I ACCESS input$xaxis?
  # Do I need to use ns? Can you do that in the server side of a module?
  output$XAXIS <- renderUI(selectInput("xaxis", "X Axis", choices = colnames(datafile())))
  output$YAXIS <- renderUI(selectInput("yaxis", "Y Axis", choices = colnames(datafile())))

  # NOT WORKING
  # Use the selectInput x and y to plot
  p <- reactive({
    req(datafile)
    # WORKS: ggplot(datafile(), aes(x = Sepal_Length, y = Sepal_Width))
    # DOES NOT WORK:
    ggplot(datafile(), aes_(x = as.name(input$xaxis), y = as.name(input$yaxis))) +
      geom_point()
  })

  return(p)
}

chartUI.R

chartUI <- function(id, label = "Create Chart") {

  ns <- NS(id)
  tagList(
    sidebarPanel(
      uiOutput(ns("XAXIS")),
      uiOutput(ns("YAXIS"))
    ),
    mainPanel(plotOutput("plot"))
  )
}
MayaGans

を使用してrenderUI関数内の名前空間を手動で指定する必要があります session$ns

chart <- function(input, output, session, datafile = reactive(NULL)) {

  # SINCE DATAFILE IS A REACTIVE WE ADD THE PRERENTHESIS HERE
  # WHERE/HOW CAN I ACCESS input$xaxis?
  # Do I need to use ns? Can you do that in the server side of a module?
  output$XAXIS <- renderUI(selectInput(session$ns("xaxis"), "X Axis", choices = colnames(datafile())))
  output$YAXIS <- renderUI(selectInput(session$ns("yaxis"), "Y Axis", choices = colnames(datafile())))

  # NOT WORKING
  # Use the selectInput x and y to plot
  p <- reactive({
    req(datafile)
    # WORKS: ggplot(datafile(), aes(x = Sepal_Length, y = Sepal_Width))
    # DOES NOT WORK:
    ggplot(datafile(), aes_(x = as.name(input$xaxis), y = as.name(input$yaxis))) +
      geom_point()
  })

  return(p)
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

光沢のあるスコープルール-モジュラーアーキテクチャでライブラリをロードする場所

分類Dev

光沢のあるモジュールで反応性を無効および有効にする方法は?

分類Dev

光沢のある呼び出しモジュール

分類Dev

forループを使用して、光沢のあるモジュールを動的な回数呼び出します

分類Dev

モジュール化された光沢のあるアプリでのggplotの配置

分類Dev

光沢のあるモジュールを反応させる

分類Dev

モジュール化された光沢のあるアプリを使用してExcelを読み取り、表示、ダウンロードする方法

分類Dev

データを共有するリアクティブな光沢のあるモジュール

分類Dev

光沢のあるモジュールを備えたupdateTabsetPanel

分類Dev

光沢のあるモジュール:ボタンのリストの処理

分類Dev

光沢のあるモジュールのリアクティブ入力による起動警告

分類Dev

モジュール内のDTの光沢のあるselectInput

分類Dev

光沢のあるモジュールのupdateSelectizeInput

分類Dev

光沢のあるモジュール間の通信

分類Dev

R条件付きパネルとリアクティブを備えた光沢のあるモジュール

分類Dev

同じ出力を作成する複数の入力モジュールを備えた光沢のあるアプリ

分類Dev

モジュール式の光沢のあるアプリでAWSS3認証情報を接続する方法

分類Dev

モジュール化された光沢のあるコードにCSSスタイルを適用するにはどうすればよいですか?

分類Dev

ObservesとreactiveValuesを備えた光沢のあるモジュール

分類Dev

モジュールでshiny.i18nを使用して光沢のあるアプリを翻訳しますか?

分類Dev

テーブルを表示するための光沢のあるモジュール

分類Dev

ある光沢のあるモジュールからの結果/出力を使用して、別のモジュール内でSelectInputを更新する

分類Dev

モジュールサーバー機能内の光沢のあるモジュールIDにアクセスします

分類Dev

cおよびc ++モジュールをアタッチする方法は?

分類Dev

insertUIを使用していくつかの光沢のあるモジュールを追加する際の問題

分類Dev

Rの検索バーモジュール光沢のある結果を返す方法

分類Dev

光沢のあるモジュール内の要素のCSSを定義する方法

分類Dev

ゴーレムフレームワークの光沢のあるパッケージ内のモジュールをテストする方法は?

分類Dev

光沢のあるモジュール:サーバー機能が失敗した場合、モジュールUIを破棄します

Related 関連記事

  1. 1

    光沢のあるスコープルール-モジュラーアーキテクチャでライブラリをロードする場所

  2. 2

    光沢のあるモジュールで反応性を無効および有効にする方法は?

  3. 3

    光沢のある呼び出しモジュール

  4. 4

    forループを使用して、光沢のあるモジュールを動的な回数呼び出します

  5. 5

    モジュール化された光沢のあるアプリでのggplotの配置

  6. 6

    光沢のあるモジュールを反応させる

  7. 7

    モジュール化された光沢のあるアプリを使用してExcelを読み取り、表示、ダウンロードする方法

  8. 8

    データを共有するリアクティブな光沢のあるモジュール

  9. 9

    光沢のあるモジュールを備えたupdateTabsetPanel

  10. 10

    光沢のあるモジュール:ボタンのリストの処理

  11. 11

    光沢のあるモジュールのリアクティブ入力による起動警告

  12. 12

    モジュール内のDTの光沢のあるselectInput

  13. 13

    光沢のあるモジュールのupdateSelectizeInput

  14. 14

    光沢のあるモジュール間の通信

  15. 15

    R条件付きパネルとリアクティブを備えた光沢のあるモジュール

  16. 16

    同じ出力を作成する複数の入力モジュールを備えた光沢のあるアプリ

  17. 17

    モジュール式の光沢のあるアプリでAWSS3認証情報を接続する方法

  18. 18

    モジュール化された光沢のあるコードにCSSスタイルを適用するにはどうすればよいですか?

  19. 19

    ObservesとreactiveValuesを備えた光沢のあるモジュール

  20. 20

    モジュールでshiny.i18nを使用して光沢のあるアプリを翻訳しますか?

  21. 21

    テーブルを表示するための光沢のあるモジュール

  22. 22

    ある光沢のあるモジュールからの結果/出力を使用して、別のモジュール内でSelectInputを更新する

  23. 23

    モジュールサーバー機能内の光沢のあるモジュールIDにアクセスします

  24. 24

    cおよびc ++モジュールをアタッチする方法は?

  25. 25

    insertUIを使用していくつかの光沢のあるモジュールを追加する際の問題

  26. 26

    Rの検索バーモジュール光沢のある結果を返す方法

  27. 27

    光沢のあるモジュール内の要素のCSSを定義する方法

  28. 28

    ゴーレムフレームワークの光沢のあるパッケージ内のモジュールをテストする方法は?

  29. 29

    光沢のあるモジュール:サーバー機能が失敗した場合、モジュールUIを破棄します

ホットタグ

アーカイブ