添加在R基上SelectInput闪亮

问题描述:

交互式菜单给定的脚本创建附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://*.com/questions/39987908/r-shinydashboard-showing-hiding-ui-elements-based-on-tab-选择) –

+0

嗨哈迪克,谢谢,我已经在这个功能,我的问题是,我们可以实现带有条件面板的selectInput,就像这个链接所说的tabset条件面板一样,还有,如果你有一个工作的例子,请分享。 –

+0

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

这里是您所提供的代码,你问输出你的工作例如:

## 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://*.com/questions/46783181/sliderinput-issue-with-table-in-r-shiny –

+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://*.com/questions/46766286/slider-not-giving-proper-value-when-pointed-at-100-in-r -shiny-table –