我正在開發一個應用程式,用戶需要通過許多選擇才能到達他/她想要進行資料分析的地方。應用程式需要通過無數的選擇輕松地“匯集”用戶,而不會混淆用戶,不會將用戶帶入死胡同等。例如,將用戶從一般選擇匯集到更具體的選擇:
- 漏斗 1:用戶選擇一個國家進行分析。在下面的 Shiny 示例中,每個選項卡都針對不同的國家/地區。用戶選擇國家進行分析
- 漏斗2:用戶在國內選擇一個省份進行分析。用戶在選項卡中選擇的國家/地區的省份串列顯示在此側邊欄面板中
- 漏斗 3:用戶想要查找所選省份的人口統計/其他資料。每個提供分析的省份統計資料都會出現一組操作按鈕,例如平均降雨量、平均溫度、兇殺率、人口、平均收入等。選擇一個操作按鈕會清除主面板并出現一系列提示在該主面板中,用戶可以繼續輸入以進行分析,并帶有回傳按鈕以回傳原始的操作按鈕主面板。為簡潔起見,這些操作按鈕/后退按鈕未呈現在影像或下面的代碼中
- 輪播:沿著主面板的頂部,當用戶轉到該主面板中的操作按鈕時,會出現一個單選按鈕選項的輪播,用于顯示資料、顯示繪圖、下載資料等操作。
下圖顯示了我正在考慮使用標簽/側邊欄/主面板的整體“漏斗”結構。在 Shiny 中,還有其他有效且清晰的方法可以通過多種選擇吸參考戶嗎?

影像中顯示的骨架結構的可重現代碼:
library(shiny)
library(shinyjs)
ui <-
pageWithSidebar(
headerPanel("Test"),
sidebarPanel(
useShinyjs(),
fluidRow(helpText(h5(strong("Base Input Panel")),align="center")),
conditionalPanel(
condition="input.tabselected==1",
h5("Selections for Tab 1:")
),
conditionalPanel(
condition="input.tabselected==2",
h5("Selections for Tab 2:")
)
), # close sidebar panel
mainPanel(
useShinyjs(),
tabsetPanel(
tabPanel("Tab 1", value=1,helpText("Tab 1 outputs")),
conditionalPanel(condition = "input.tabselected==1",
fluidRow(helpText("Tab 1 things happen here")),
),
tabPanel("Tab 2", value=2,
fluidRow(
radioButtons(
inputId = 'mainPanelBtnTab2',
label = h5(strong(helpText("Functions to access:"))),
choices = c('Function 1','Function 2','Function 3'),
selected = 'Function 1',
inline = TRUE
) # close radio buttons
), # close fluid row
conditionalPanel(condition = "input.tabselected==2",
fluidRow(helpText("Tab 2 things happen here")),
conditionalPanel(condition = "input.mainPanelBtnTab2 == 'Function 1'",
helpText("You pressed radio button 1")),
conditionalPanel(condition = "input.mainPanelBtnTab2 == 'Function 2'",
helpText("You pressed radio button 2")),
conditionalPanel(condition = "input.mainPanelBtnTab2 == 'Function 3'",
helpText("You pressed radio button 3"))
) # close conditional panel
), # close tab panel
id = "tabselected"
) # close tabsetPanel
) # close mainPanel
) # close pageWithSidebar
server <- function(input,output,session)({})
shinyApp(ui, server)
uj5u.com熱心網友回復:
解決此問題的一種方法是updateSelectInput在服務器端更新輸入選項。如果您在資料框中定義國家、省和變數的所有組合,則可以根據用戶輸入過濾此資料框。
在下面的簡化示例中,省的選項會根據國家/地區選擇進行更新。您可以為具有類似邏輯的變數型別添加第三層。
library(shiny)
df <- data.frame(
country = c(rep("U.S.", 2), rep("Canada", 2)),
province = c("California", "Oregon", "British Colulmbia", "Alberta")
)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("country", "Country", unique(df$country), multiple = T),
selectInput("province", "Province:", "Select a country first", multiple = T)
),
mainPanel(
)
)
)
server <- function(input, output, session) {
observe({
# update options based on country selection
province_list <- df %>%
filter(country %in% input$country)
# update selector
updateSelectInput(session, "province", "Province:", choices = unique(province_list$province))
})
}
shinyApp(ui = ui, server = server)

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/511694.html
上一篇:RShiny是否可以在父選項卡下設定子選項卡,以便為用戶提供更好的選擇渠道?
下一篇:UI背景隨縱橫比變化
