我想创建一个闪亮的应用程序,用户可以在其中查看来自两个不同数据集的数据:' new'和'中央'。
我使用以下代码:
# Define UI for application
fluidPage(
titlePanel("Public services"),
#tell shiny where to display the objects
#let the user choose the dataset they want to interact with
sidebarLayout(
sidebarPanel(
selectInput("dataset", "Choose dataset:",
choices = c("Local government", "Central Government")),
uiOutput('name'),
uiOutput('type'),
uiOutput('service')),
#display an output object on the main manel
mainPanel(
# Output: Verbatim text for data summary ----
h4("Summary"),
verbatimTextOutput("summary"),
h4("Observations"),
DT::dataTableOutput("table")
))
)
# Define UI for application that
function(input, output) {
# A reactive expression to return the dataset corresponding to the
user choice
datasetInput <- reactive({
switch(input$dataset,
"Central Government" = central,
"Local Government" = local)
})
#Filter data based on selections
#name
output$name = renderUI({
selectInput('name', h5('Department or Local authority name'),
choices = names(datasetInput()))
})
output$type = renderUI({
selectInput('type', h5('Service type'), choices =
names(datasetInput()))
})
output$service = renderUI({
selectInput('service', h5('Service'), choices =
names(datasetInput()))
})
output$table <- DT::renderDataTable({
datasetInput()
})
}
只有&#39;中心&#39;数据集在数据框中查看,输入选项仅在“中心”中可见。数据集。
答案 0 :(得分:0)
下面的代码,只是你的代码中遗漏了一些部分和不同的数据集,对我来说运行正常。没有可重复的例子 有点难以帮助你,因为我无法重现错误的行为。如果您可以添加一个可重现的示例,那将会很棒,例如here或here就可以看到提示。
# Define UI for application
ui<- fluidPage(
titlePanel("Public services"),
#tell shiny where to display the objects
#let the user choose the dataset they want to interact with
sidebarLayout(
sidebarPanel(
selectInput("dataset", "Choose dataset:",
choices = c("mtcars2", "mtcars10"))),
mainPanel(
DT::dataTableOutput("table")
))
)
# Define UI for application that
server<-function(input, output) {
# A reactive expression to return the dataset corresponding to the
datasetInput <- reactive({
switch(input$dataset,
"mtcars2" = head(mtcars,2),
"mtcars10" = head(mtcars,10))
})
output$table <- DT::renderDataTable({
datasetInput()
})
}
shinyApp(ui,server)