2016-10-06 5 views
3

私はShiny Appの "selectInput"と "updateSelectInput"の組み合わせに問題があります(私はShinyを初めて使っていますが、その質問に対する回答はどこにも見つからないようです)。次の基本的な例のように、ラベルをhtmlタグでフォーマットします(たとえば、2行に分割してフォントサイズを変更するなど)。これは "selectInput"ではうまく動作しますが、 "updateSelectInput"は同じラベルをダイジェストできず、 "[object Object]"を出力します。 htmlタグを扱うことができないようです。そのための回避策はありますか?ありがとう!updateSelectInputラベルは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")) 
    }) 
}) 

答えて

1

あなたが達成したいものをあなたの説明/コード内で明確ではありません。つまり、updateSelectInputのラベルを変更しているので、updateコマンドでラベルを繰り返す必要はありません。また、あなたの観測には入力がありません(何もしません)。入力$ choice1に反応するコードを変更しますが、choice2の選択肢を更新するコードを追加する必要があります。

また、/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) 
+0

こんにちはロン、あなたの迅速な応答をありがとう。まず、updateSelectInputにラベルをコメントアウトするには私の問題を解決しました!!!が、私はselectInputが最初に受け入れるのと同じことを、なぜ受け入れないのかまだ分かりません。アイデアは何ですか?私は観察の中に何も含めませんでした。なぜなら、それはポイントの外にあったからです。それでは、もう一度ありがとう! – humuskopf

+0

updateSelectInputはトリッキーです。また、selectInputでlabel = NULLを設定し、UIのコントロールの上、またはrenderUI/uiOutputを使用してサーバー上のhtml段落としてラベルを追加することもできます。私は通常、もっと柔軟性があるので、そうします。 –

+0

OK、ありがとうRon!少なくとも私はこれを今知っている! – humuskopf

関連する問題