ボタンをクリックしたときにuiOutput()
とplotOutput()
を使用してUIを変更したい。イベントを待たずにすぐにコンテンツを変更すると、すべてうまく動作します。ボタンをクリックしたときにoutput$body.immediately
と同じ出力を持つoutput$body.on.button
に変更する必要はありますか?R Shiny:eventReactive()内で出力関数が機能しない
server.R:
shinyServer(function(input, output, session) {
output$plot <- renderPlot({plot(1:5)})
output$body.ui <- renderUI({tags$p('This works only within renderUI')})
output$body.on.button <- eventReactive(input$goButton, {
switch(
input$select,
"text" = 'This works within both functions',
"ui" = uiOutput("body.ui"), # This doesn't work
"plot" = plotOutput("plot") # This doesn't work
)
})
output$body.immediately <- renderUI({
switch(
input$select,
"text" = 'This works within both functions',
"ui" = uiOutput("body.ui"), # This works
"plot" = plotOutput("plot") # This works
)
})
})
ui.R:
library(markdown)
shinyUI(
navbarPage(
"Title",
tabPanel(
"First element",
fluidRow(
column(
4,
wellPanel(
selectInput("select", "Select", c('text', 'ui', 'plot')),
actionButton("goButton", "Go!")
) # end of wellPanel
), # end of column
column(
4,
uiOutput("body.immediately")
), # end of column
column(
4,
uiOutput("body.on.button")
) # end of column
) # end of fluidROw
) # end of tabPanel
) # end of navbarPage
) # end of shinyUI
私はまた、機能observeEvent()
を試してみましたが、それは助けにはなりませんでした。
ありがとう!二重性は意図的に機能することを確認するために作成されました(ただし、余分な問題を引き起こす可能性はありません)。この解決策は 'renderUI()'関数内にあります。それは今正常に動作します –