updateSelectInput 标签不接受 HTML 标签?
updateSelectInput label doesn't accept HTML tags?
我的 Shiny 应用程序中 "selectInput" 和 "updateSelectInput" 的组合有问题(我是 Shiny 的新手,但似乎找不到该问题的答案任何地方)。我想用 html 标签格式化标签,如下面的基本示例所示(例如,分成两行,更改字体大小)。这对 "selectInput" 工作得很好,但是 "updateSelectInput" 不能消化相同的标签,它输出“[object Object]”。在我看来,它无法处理 html 标签。有什么解决方法吗???谢谢!
ui.R:
# Load libraries needed for app
library(shiny)
library(shinydashboard)
# Define the overall UI with a dashboard page template
shinyUI(
dashboardPage(
dashboardHeader(title = "dashboard header"),
dashboardSidebar(
#Create first dropdown box
selectInput("choice1", "First choice:",1:5,selected=NULL),
#Create second dropdown box
selectInput("choice2", p("Then, make your ", tags$br(), tags$small("second choice")), c("a","b","c","d","e"))
),
dashboardBody()
)
)
server.R:
# Load libraries needed for app
library(shiny)
library(shinydashboard)
# Define server for the Shiny app
shinyServer(function(input, output,session) {
# populate second dropdown box when a choice in first dropdown box is made
observe({
updateSelectInput(session, "choice2", p("Then, make your ", tags$br(), tags$small("second choice")), c("a","b","c","d","e"))
})
})
你的 description/code 不清楚你想要完成什么。也就是说,您注意到在 updateSelectInput 中更改了标签,因此无需在更新命令中重复标签。你的观察中也没有输入(,它什么都不做。我将代码更改为对输入 $choice1 做出反应,但是你需要添加一些代码来更新 choice2 中的选择。
您也可以使用 renderUI/uiOutput 更新服务器中的控件,这样您就可以避免标签出现问题。
# Load libraries needed for app
library(shiny)
library(shinydashboard)
# Define server for the Shiny app
server <- shinyServer(function(input, output,session) {
# populate second dropdown box when a choice in first dropdown box is made
observeEvent( input$choice1 ,{
updateSelectInput(session = session,
inputId = "choice2",
# label = p("Then, make your ", tags$br(), tags$small("second choice")),
choices = c("a","b","c","d","e"))
})
})
# Define the overall UI with a dashboard page template
ui <- shinyUI(
dashboardPage(
dashboardHeader(title = "dashboard header"),
dashboardSidebar(
#Create first dropdown box
selectInput(inputId = "choice1",
label = "First choice:",
choices = 1:5,
selected=NULL),
#Create second dropdown box
selectInput(inputId = "choice2",
label = p("Then, make your ", tags$br(), tags$small("second choice")),
choices = c("a","b","c","d","e"))
),
dashboardBody()
)
)
shinyApp(ui, server)
我的 Shiny 应用程序中 "selectInput" 和 "updateSelectInput" 的组合有问题(我是 Shiny 的新手,但似乎找不到该问题的答案任何地方)。我想用 html 标签格式化标签,如下面的基本示例所示(例如,分成两行,更改字体大小)。这对 "selectInput" 工作得很好,但是 "updateSelectInput" 不能消化相同的标签,它输出“[object Object]”。在我看来,它无法处理 html 标签。有什么解决方法吗???谢谢!
ui.R:
# Load libraries needed for app
library(shiny)
library(shinydashboard)
# Define the overall UI with a dashboard page template
shinyUI(
dashboardPage(
dashboardHeader(title = "dashboard header"),
dashboardSidebar(
#Create first dropdown box
selectInput("choice1", "First choice:",1:5,selected=NULL),
#Create second dropdown box
selectInput("choice2", p("Then, make your ", tags$br(), tags$small("second choice")), c("a","b","c","d","e"))
),
dashboardBody()
)
)
server.R:
# Load libraries needed for app
library(shiny)
library(shinydashboard)
# Define server for the Shiny app
shinyServer(function(input, output,session) {
# populate second dropdown box when a choice in first dropdown box is made
observe({
updateSelectInput(session, "choice2", p("Then, make your ", tags$br(), tags$small("second choice")), c("a","b","c","d","e"))
})
})
你的 description/code 不清楚你想要完成什么。也就是说,您注意到在 updateSelectInput 中更改了标签,因此无需在更新命令中重复标签。你的观察中也没有输入(,它什么都不做。我将代码更改为对输入 $choice1 做出反应,但是你需要添加一些代码来更新 choice2 中的选择。
您也可以使用 renderUI/uiOutput 更新服务器中的控件,这样您就可以避免标签出现问题。
# Load libraries needed for app
library(shiny)
library(shinydashboard)
# Define server for the Shiny app
server <- shinyServer(function(input, output,session) {
# populate second dropdown box when a choice in first dropdown box is made
observeEvent( input$choice1 ,{
updateSelectInput(session = session,
inputId = "choice2",
# label = p("Then, make your ", tags$br(), tags$small("second choice")),
choices = c("a","b","c","d","e"))
})
})
# Define the overall UI with a dashboard page template
ui <- shinyUI(
dashboardPage(
dashboardHeader(title = "dashboard header"),
dashboardSidebar(
#Create first dropdown box
selectInput(inputId = "choice1",
label = "First choice:",
choices = 1:5,
selected=NULL),
#Create second dropdown box
selectInput(inputId = "choice2",
label = p("Then, make your ", tags$br(), tags$small("second choice")),
choices = c("a","b","c","d","e"))
),
dashboardBody()
)
)
shinyApp(ui, server)