给定的脚本创建附加的快照。它是在R中使用DT包创建的表。我想在表格上方创建菜单,以便通过选择输入" A"在第一个SelectInput中,我得到第二个带有两个滑块的selectInput,同时选择" B"在第一个SelectInput中,我应该只获得第二个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)
答案 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)))
})
}
))
答案 1 :(得分: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)
正如评论中所述,诀窍是使用conditionalPanel
。