0
私は最初のShiny Appを作成しようとしており、基本的に2つの単純なヒストグラムをプロットするようにしていますが、入力ボタンを使用して2つのヒストグラムを並べて表示するかどうかを選択できます横に)または上下に1つ(垂直に)。Shiny Appの入力ボタンを使用してレイアウトを反応的に変更するにはどうすればよいですか?
実際にはうまくいくと思っているよりも、自分の思考プロセスを説明するために、以下のコードを書きました。
ご協力いただきありがとうございます!
library(shiny)
ui <- fluidPage(
radioButtons('layout', 'Layout:', choices=c('Vertically', 'Horizontally'), inline=TRUE),
sliderInput(inputId = "num",
label = "Choose a number",
value = 25, min = 1, max = 100),
plotOutput("hist1"),
plotOutput("hist2"))
server <- function(input,output) {
if (input$layout == "Horizontally") {
output$hist1<-fluidRow(
column(3,plotOutput(hist(rnorm(input$num)))))
output$hist2<-column(3,plotOutput(hist(rnorm(input$num))))
}
else if (input$layout == "Vertically") {
output$hist1<-fluidRow(
column(3,plotOutput(hist(rnorm(input$num)))))
output$hist2<-fluidRow(
column(3,plotOutput(hist(rnorm(input$num)))))
}
}
shinyApp(ui=ui, server=server)
グレート、ありがとう!常に物事を並べて表示することを考慮すると、1つのヒストグラム、あるいはその両方を表示したい場合は、代わりに入力ボタンを選択する方法がありますか? – lc23
はい、あなたのニーズに合わせてrenderUIのコンテンツを変更するだけです – HubertL