shinydashboard
앱에서 사용하는 sampledata.csv
이라는 CSV 파일에 다음과 같은 간단한 데이터가 있습니다.탭을 재설정 할 때 반짝이는 dateRange를 설정하는 방법
date category
1/1/2001 1M
1/2/2001 1M
1/3/2001 1M
1/4/2001 1M
1/5/2001 1M
1/1/2002 2M
1/2/2002 2M
1/3/2002 2M
1/4/2002 2M
1/5/2002 2M
가 나는 app.R
파일에 다음 shinydashboard
코드를 가지고 :
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(id='tab',
menuItem('Tab 1', tabName='tab1'),
menuItem('Tab 2', tabName='tab2')
)
),
dashboardBody(
tabItems(
tabItem(tabName='tab1',
uiOutput('daterange')
),
tabItem(tabName='tab2',
verbatimTextOutput('range')
)
)
)
)
sample <- read.csv('sampledata.csv')
sample$date <- as.Date(sample$date, '%m/%d/%Y')
server <- function(input, output, session) {
#Observe which tab is selected
observe({
print(input$tab)
})
subdata <- reactive({
#Subset to include only sample$category=='1M' when any tab is selected
if(input$tab=="tab1" | input$tab=="tab2"){
sample <- sample[which(sample$category=='1M'),]
}
return(sample)
})
output$daterange <- renderUI({
#Set daterange to go from min to max of subdata()
dateRangeInput(inputId='daterange',
label='Select Period',
min=min(subdata()$date), max=max(subdata()$date)
)
})
output$range <- renderPrint(input$daterange)
}
shinyApp(ui, server)
내가 tab1
에서 tab2
에, daterange
재설정을 얻는다 변경하는 경우, 응용 프로그램을 사용할 때 내 문제입니다. 따라서 tab1
에 시작일 또는 종료일을 변경 한 다음 tab2
을 클릭하면 더 이상 선택한 날짜가 유지되지 않습니다. 위의 코드에서 subdata
의 if
문이 중복 된 것처럼 보입니다. 제거하면 문제가 사라집니다. 그러나 실제로는 어떤 탭이 선택되었는지에 따라 더 복잡한 앱과 하위 데이터가 변경됩니다. if
문을 유지하는 방법이 있지만 탭을 변경할 때 daterange
이 재설정되지 않았습니까?
를 분리 할 수 있습니다. 나는 그것을 몸 속에 유지하고 싶다. –
'isolate'로 작동해야합니다. 내 첫 번째 게시물을 편집했습니다. –
여전히 작동하지 않습니다. 'isolate '와 같은 문제가 발생합니다. –