r - How to add the same inputs into two tabItems in shinydashboard? -
i using shinydashboard create interface of shiny app. want 1 input appear in 2 tabmenu. in example below, want textinput
i_test
appears in menu menu1
, menu2
.
how should implement it? suggestions.
library(shiny) library(shinydashboard) # side bar boardy sidebar <- dashboardsidebar( sidebarmenu( id = 'menu_tabs' , menuitem('menu1', tabname = 'menu1') , menuitem('menu2', tabname = 'menu2') , menuitem('menu3', tabname = 'menu3') ) ) # body board body <- dashboardbody( tabitems( tabitem( tabname = 'menu1', textinput('i_test', 'test') ), tabitem( tabname = 'menu2' ) ) ) # shiny ui ui <- dashboardpage( title = 'test', dashboardheader(), sidebar, body ) server <- function(input, output, session) { } shinyapp(ui, server)
it seems shiny renders 2 distinct elements, if try build same element second time.
thats why come solution makes 2 text iputs same.
check code:
library(shiny) library(shinydashboard) # side bar boardy sidebar <- dashboardsidebar( sidebarmenu( id = 'menu_tabs' , menuitem('menu1', tabname = 'menu1') , menuitem('menu2', tabname = 'menu2') , menuitem('menu3', tabname = 'menu3') ) ) # body board body <- dashboardbody( tabitems( tabitem( tabname = 'menu1', textinput('i_test_1', 'test') ), tabitem( tabname = 'menu2', textinput('i_test_2', 'test') ), tabitem( tabname = 'menu3' ) ) ) # shiny ui ui <- dashboardpage( title = 'test', dashboardheader(), sidebar, body ) server <- function(input, output, session) { observe({ text1 <- input$i_test_1 updatetextinput(session, 'i_test_2', value = text1) }) observe({ text2 <- input$i_test_2 updatetextinput(session, 'i_test_1', value = text2) }) } shinyapp(ui, server)
Comments
Post a Comment