1
私はユニークなプロットをレンダリングできるシンプルなシャイニーアプリを持っています。私は、ユーザーが複数の変数をチェックし、対応するプロットを(単純なプレゼンテーションで、お互いの上に積み重ねて)表示できるようにすることで、このアプリケーションを改善したいと考えています。R Shiny - checkboxGroupInputで選択された複数のプロットを表示
UIのoutputPlot
機能でfor
のループを試してみましたが、サーバーコールではrenderPlot
の機能が成功しませんでした。どのようなアイデアや手掛かりがこの問題を解決する?
# Library and function
library(ggplot2)
library(shiny)
CountPlotFunction <- function(MyData)
{
MyPlot <- ggplot(data = MyData, aes(x = MyData)) +
geom_bar(stat = "count", aes(fill = MyData)) +
geom_text(stat = "count", aes(label = ..count..)) +
scale_x_discrete(drop = FALSE) +
scale_fill_discrete(drop = FALSE)
return(MyPlot)
}
# The data
var1 <- c("Russia","Canada","Australia","Australia","Russia","Australia","Canada","Germany","Australia","Canada","Canada")
var2 <- c("UnitedStates","France","SouthAfrica","SouthAfrica","UnitedStates","SouthAfrica","France","Norge","SouthAfrica","France","France")
var3 <- c("Brazil","Colombia","China","China","Brazil","China","Colombia","Belgium","China","Colombia","Colombia")
df <- data.frame(var1, var2, var3)
# The Shiny app
Interface <-
{
fluidPage(
sidebarPanel(
checkboxGroupInput(inputId = "Question",
label = "Choose the question",
choices = colnames(df),
selected = colnames(df)[1])),
mainPanel(plotOutput(outputId = "ThePlot")))
}
Serveur <- function(input, output)
{
output$ThePlot <- renderPlot({CountPlotFunction(MyData = df[input$Question])})
}
shinyApp(ui = Interface, server = Serveur)