如何在R的新标签窗口中显示输出?

时间:2016-08-22 08:32:18

标签: r shiny

如何在R?

的新选项卡中显示renderUI内定义的输出
observeEvent (input$button1, {
 output$details1 <- renderUI({    
fluidPage(    
      fluidRow(    
     #This part contains R statements including textboxes,checkboxes etc to be displayed in another tab window
      ))                
})})

2 个答案:

答案 0 :(得分:0)

您的问题质量低,我不能100%确定这是您想要/需要的。

您基本上定义了一个 tabset ,只需将某些输入或输出元素的表达式放在这些标签中:

library(shiny)

ui <- shinyUI(fluidPage(
  headerPanel("Tabsets"),

  mainPanel(
    tabsetPanel(
      tabPanel("Tab 1", actionButton(inputId="button1", "Go!")), 
      tabPanel("Tab 2", uiOutput("details1"))
    )
  )
))

server <- shinyServer(function(input, output) {
  observeEvent (input$button1, {
    output$details1 <- renderUI({    
        fluidRow(    
          renderText({ "Yeah!" })
        )                
    })})
})

shiny::shinyApp(ui=ui,server=server)

答案 1 :(得分:0)

单击按钮时,可以使用updateTabsetPanel更改为新选项卡。

library(shiny)

ui <- shinyUI(fluidPage(  
    tabsetPanel(type = "tabs", id = 'myTabs' 
              ,tabPanel(title = "Tab1",value = "tab1" ,actionButton(inputId="button1", "Go!") ), 
              tabPanel(title = "Tab2", value = "tab2",    uiOutput('details1')  )
    ) 
)) 

server <- shinyServer(function(input, output, session) {  
    observeEvent(input$button1 , { 
      updateTabsetPanel(session = session 
          ,inputId = 'myTabs'
          ,selected = 'tab2')
    }) 
    output$details1 <- renderUI({   
       textInput(inputId = 'Age', label = 'Age', value = 23) 
    })         
})   

shiny::shinyApp(ui=ui,server=server)