前提
R Shiny で WEBアプリっぽいものを作っています。
RSttudio を使って、Consoleにデバッグ情報を出力させながら開発を進めています。
実現したいこと
selectInput の choices を、動的に生成する必要がありました。そこで、server.R のほうで、 renderUI をおこない、 ui.R で uiOutput で受け取って表示するようにしました。
ui.R では、actionButton を持っており、このボタンを押したときに、 情報を再描画させたいがため、 server.R で eventReactiveで ボタンの押されたことを感知して処理するようにしたいです。
この eventReactive のなかで、 uiOutput で表示敷いている selectInput の値を読み取りたいのです。
発生している問題・エラーメッセージ
eventReactive のなかで、 str(input$select_country と行って、 selectInput の inputid を指定してみましたが・・・
List of 2 $ 0 :List of 2 ..$ jQuery360037919148499739922:List of 2 .. ..$ _shiny_initialized: logi TRUE .. ..$ shinyInputBinding : Named list() ..$ jQuery360037919148499739921:List of 1 .. ..$ events:List of 1 .. .. ..$ change:List of 1 .. .. .. ..$ :List of 4 .. .. .. .. ..$ type : chr "change" .. .. .. .. ..$ origType : chr "change" .. .. .. .. ..$ guid : int 109 .. .. .. .. ..$ namespace: chr "shinysky-select2Input" $ length: int 1
これは、入力情報ではなくて入力UIの在り方情報みたいですね・・・。
該当のソースコード
R
1(sever.R から関連部分抜粋) 2 3shinyServer(function(input, output) { 4 5 output$select_country <- renderUI({ 6 if (is.null(Data()$df)) {return()} 7 else { 8 countryS <- unique(unlist(Data()$df$co)) 9 #str(countryS) 10 selectInput("select_country", label = "Country", choices = countryS) 11 } 12 }) 13 14 Data = eventReactive(input$submit, { 15 str(input$select_country) 16 return("<ここに select_country で選ばれた値を出力したい>") 17 } 18}
R
1(ui.R から関連部分抜粋) 2shinyUI(fluidPage( 3 p("Country"), 4 uiOutput("select_country"), 5 actionButton("submit", "Submit", styleclass = "primary") 6))
試したこと
ui.R 側で記述してしまえる input のアイテムは、 server.R で input で読み取りますので、renderUI と uiOutput の利用の場合も同じようにできるのかな、と思ったのですが、違ったようです。
動的なselectInput choices の使い方がそもそも間違ってるのでしょうか。 renderUI で作らない、とか?
補足情報(FW/ツールのバージョンなど)
R 4.2.2
RSTUDIO-2022.12.0-353-AMD64.DEB
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/01/11 12:15
2023/01/12 02:09