1

私はこれにかなり慣れていないので、ご容赦ください。アップロードされた固定形式のデータ ファイルを取得し、ユーザーの選択に基づいてさまざまなプロットをレンダリングするアプリを Shiny で構築しています。アプリの重要な部分の 1 つは、それぞれ 1 つのプロットを含む一連のタブです。

タブをレンダリングするためにrenderUIを使用していますが、プロットをレンダリングするのが非常に困難です。renderPlot、outputPlot を試しましたが、プロットを表示できません。さまざまなエラーが発生しますが、以下のコードは、renderPlot(engPlot) の時点で「as.character(x) のエラー: 型 'closure' を型 'character' のベクトルに強制することはできません」を生成しています。

ui.R

# Define UI
shinyUI(fluidPage(
# Application title
  titlePanel("Chart Creation Tool"),
# Sidebar
sidebarLayout(
   sidebarPanel(
      fileInput("fileBlob", "Upload File", multiple = FALSE, accept = NULL),
      selectInput("selectAnalysis", label=h3("Select Input"), choices=c("Month x Year", "Strategies", "Programs", "Segments")),
   uiOutput("strategyList")
),

# Show a plot of the generated distribution
mainPanel(
  uiOutput("mainPanel")      
)
)
))

server.R の mainPanel 部分

output$mainPanel <- renderUI ({

if (length(RawImport())==0L) {

  out <- NULL

}else{
  if (input$selectAnalysis=="Month x Year") {
    dfAggMonth <- aggregate(cbind(Sent,Delivered,UniqueOpens,Responders,Bounced,Unsubscribes,TotalSpamComplaints,HardBounces,SoftBounces) ~ SentMonth + SentYear + SentMonthName, RawImport(), FUN = sum)
    dfAggMonth <- addRatios(dfAggMonth)
    dfAggMonth <- dfAggMonth[with(dfAggMonth, order(Date)), ]

    engPlot <- runplot(paste(dfAggMonth$SentMonthName, dfAggMonth$SentYear,sep="-"), dfAggMonth$Date, dfAggMonth$Delivered, dfAggMonth$UniqueOpenRate, dfAggMonth$ResponderRate, "engagement", , "Temp Title")

    out <- tabsetPanel(
      tabPanel("Engagement", "Engagement", renderPlot(engPlot)), 
      tabPanel("Summary", "summary", "summary"),
      tabPanel("Deliverability",runplot(paste(dfAggMonth$SentMonthName, dfAggMonth$SentYear,sep="-"), dfAggMonth$Date, dfAggMonth$Delivered, dfAggMonth$BounceRate, , "deliverability", , "Temp Title"))
      )  
  }
  else {
    out <- tabsetPanel(
      tabPanel("Tab 1", input$selectAnalysis), 
      tabPanel("Tab 2", input$selectAnalysis)
    )
  }

}

out
})

RunPlot 関数

runplot <- function(xSeriesLabels, xSeriesValues, leftseries, rightseries1, rightseries2, chartType, columnSeries, xTitle){

if (missing(xTitle)==FALSE) {
   strTitle <- xTitle
  } else {
    strTitle <- "no title supplied"
  }


  p <- barplot(leftseries, width=1, col=barCol, axisnames = leftseries, names.arg=xSeriesLabels, axis.lty=1, xlab=strTitle)

  return(p)
}
4

1 に答える 1

2

で実行することを意図した関数を実行しているときに、このエラーが頻繁に発生することがわかりましserver.Rui.R

renderUIしたがって、本格的なクライアント側 UI を作成することを覚えておく必要があります。つまり、動的 UI で返すコードはすべて (たまたま に格納されている場合でも) にserver.R存在する可能性のある有効なクライアント側コードでなければならないということですui.R。動的に作成しようとしているコード (tabsetPanels の 1outつなど) を使用して、ui.R動作するかどうかを確認してください。これにより、将来のデバッグが容易になる可能性があります。

renderPlotこの場合、それを行った場合に発生する問題は、呼び出しに関するものだと思います。ここでは動的 UI を作成しているだけなので、UI 互換関数 (plotOutput("plotName")この場合は ) を使用する必要があります。次に、サーバー側で、その出力にプロットを割り当てます。

output$plotName <- renderPlot({
 ...
})

プロットが表示されている場合は必要なことを行い、プロットが表示されていない場合は目に見える効果はありません。

于 2014-04-07T14:45:08.733 に答える