2017-10-16 165 views
1

交互式菜單給定的腳本創建附snapshot.It是使用DT包在R.我想通過選擇輸入「A」,以使表上面的菜單,使得表中創建在第一個SelectInput中,我得到第二個selectInput和兩個滑塊,在第一個SelectInput中選擇「B」,我應該只有第二個SelectInput和滑塊。桌上虹膜沒有需要改變。請幫助和謝謝。添加在R基上SelectInput閃亮

## app.R ## 
library(shiny) 
library(shinydashboard) 
library(DT) 

#Declaring the UI 
ui <- fluidPage(
titlePanel("Interactive Menu"), 

# Create a new Row in the UI for selectInputs 
fluidRow(
column(3, 
    selectInput("names", 
       "Customer:", 
       c("A","B")) 
)), 
fluidRow(

column(4, 
     selectInput("names", 
        "Customer:", 
        c(as.character(iris$Species))) 
), 
column(4, 
     sliderInput("slide", "Select the slider one", 
        min = 75, max = 100, 
        value = 75, step = 5) 

), 
column(4, 

     sliderInput("city", "Select the slider two", 
        min = 60, max = 100, 
        value = 60, step = 10) 
)), 

# Create a new row for the table. 
fluidRow(
DT::dataTableOutput("table1") 
) 
) 
#Declaring the Server 
server <- function(input, output) { 

# Filter data based on selections 
output$table1 <- renderDataTable({ 

datatable(iris, options = list(
    searching = FALSE, 
    pageLength = 5, 
    lengthMenu = c(5, 10, 15, 20) 
)) 
}) 
} 
shinyApp(ui, server) 

iris_capture

+1

的[R Shinydashboard顯示/隱藏UI元素基於標籤選擇]可能的複製(https://stackoverflow.com/questions/39987908/r-shinydashboard-showing-hiding-ui-elements-based-on-tab-選擇) –

+0

嗨哈迪克,謝謝,我已經在這個功能,我的問題是,我們可以實現帶有條件面板的selectInput,就像這個鏈接所說的tabset條件面板一樣,還有,如果你有一個工作的例子,請分享。 –

+0

你可以在'renderUI'中使用'conditionalPanel'或'uiOutput'。 – SBista

回答

0

這裏是您所提供的代碼,你問輸出你的工作例如:

## app.R ## 
library(shiny) 
library(shinydashboard) 
library(DT) 

#Declaring the UI 
ui <- fluidPage(
    titlePanel("Interactive Menu"), 

    # Create a new Row in the UI for selectInputs 
    fluidRow(
     column(4, 
     selectInput("names", 
        "Customer:", 
        c("A","B"))) 
    ) 
    , 
    fluidRow(
    conditionalPanel(
     condition = "input.names == 'A'", 
     column(4, 
      selectInput("names", 
         "Customer:", 
         c(as.character(iris$Species))) 
      ), 
     column(4, 
      sliderInput("slide", "Select the slider one", 
         min = 75, max = 100, 
         value = 75, step = 5)), 
     column(4, 
      sliderInput("city", "Select the slider two", 
         min = 60, max = 100, 
         value = 60, step = 10) 
    ) 
    ), 
    conditionalPanel(
     condition = "input.names == 'B'", 
    column(4, 
      selectInput("names", 
         "Customer:", 
         c(as.character(iris$Species))) 
      )) 
    ), 

    # Create a new row for the table. 
    fluidRow(
    DT::dataTableOutput("table1") 
) 
) 
#Declaring the Server 
server <- function(input, output) { 

    # Filter data based on selections 
    output$table1 <- renderDataTable({ 

    datatable(iris, options = list(
     searching = FALSE, 
     pageLength = 5, 
     lengthMenu = c(5, 10, 15, 20) 
    )) 
    }) 
} 
shinyApp(ui, server) 

enter image description here

enter image description here

正如評論中所述,訣竅是使用conditionalPanel

+0

偉大的安託萬,我喜歡這個,完美的點。 –

+0

請與此鏈接https://stackoverflow.com/questions/46783181/sliderinput-issue-with-table-in-r-shiny –

+0

幫助請接受的答案,如果你發現它是有用的。 –

0

您可以添加像這樣多個部件:

rm(list = ls()) 
library(shiny) 
runApp(list(
    ui = bootstrapPage(
    selectInput('data', 'Data', c('mtcars', 'iris')), 
    uiOutput('columns') 
), 
    server = function(input, output){ 
    output$columns <- renderUI({ 
     mydata <- get(input$data) 
     tagList(
     selectInput('columns2', 'Columns', names(mydata)), 
     selectInput('columns3', 'Columns 2', names(mydata))) 
    }) 
    } 
)) 
+0

謝謝,很有幫助。 –

+0

嘿,我需要這個帖子一點點的幫助,如果你能幫助我,https://stackoverflow.com/questions/46766286/slider-not-giving-proper-value-when-pointed-at-100-in-r -shiny-table –