2016-08-25 1 views
0

두 개의 rhandsontables을 하나의 반짝이는 앱에 넣으면 반짝이는 선이 뒤섞입니다. 두 번째 표가 첫 번째 표와 동일한 스파크 라인을 포함하는 동안 첫 번째 표의 스파크 라인이 올바르게 표시되거나 그 반대의 경우도 마찬가지입니다. 그러나, 다른 tabPanels에서 "플롯"되어도 괜찮습니다.하나의 탭에 두 개의 주축 부품 반짝이는 앱의 패널

두 개의 결합 방법이 있습니까 rhandsontablestabPanel?

library(shiny) 
library(dplyr) 
library(rhandsontable) 

#example data set1 
dat1 <- data.frame(a=sample(1:10, 10), b=sample(1:10, 10), c=sample(1:10, 10), d=sample(1:10, 10), e=sample(1:10, 10)) 
dat1$a1 <- sapply(1:nrow(dat1), function(x) jsonlite::toJSON(list(values=c(as.numeric(dat1$a[x]), as.numeric(dat1$b[x]), as.numeric(dat1$c[x]), as.numeric(0)), options = list(type = "line")))) 

dat1$a2 <- sapply(1:nrow(dat1), function(x) jsonlite::toJSON(list(values=c(as.numeric(dat1$d[x]), as.numeric(dat1$e[x]), as.numeric(0)), options = list(type = "line")))) 

#example data set1 
dat2 <- data.frame(a=sample(1:10, 10), b=sample(1:10, 10), c=sample(1:10, 10), d=sample(1:10, 10), e=sample(1:10, 10)) 
dat2$a1 <- sapply(1:nrow(dat2), 
       function(x) jsonlite::toJSON(list(values=c(as.numeric(dat2$a[x]), as.numeric(dat2$b[x]), as.numeric(dat2$c[x]), as.numeric(0)), options = list(type = "bar")))) 
dat2$a2 <- sapply(1:nrow(dat2), 
       function(x) jsonlite::toJSON(list(values=c(as.numeric(dat2$d[x]), as.numeric(dat2$e[x]), as.numeric(0)), options = list(type = "bar")))) 



runApp(launch.browser = TRUE, 
    list(ui=shinyUI(fluidPage(

    titlePanel("MYTITLE"), 
    mainPanel(
     tabPanel("A", 
       rHandsontableOutput("first"), 
       br(), 
       rHandsontableOutput("second")) 

    ) 
    )), 
    server = function(input, output) { 

     output$first <- renderRHandsontable({ 
     dat1 %>% 
     select(a, b, c, a1, d, e, a2)%>% 
     rhandsontable(readOnly = TRUE, width = 800, 
         allowedTags = "<em><b><span><strong><a><big>") %>% 
     hot_cols(colWidths = c(50, 50, 50,80, 50, 50, 80)) %>% 
     hot_col("a", format = "0")%>% 
     hot_col("b", format = "0") %>% 
     hot_col("c", format = "0") %>% 
     hot_col("d", format = "0") %>% 
     hot_col("e", format = "0") %>% 
     hot_col("a1", renderer = htmlwidgets::JS("renderSparkline")) %>% 
     hot_col("a2", renderer = htmlwidgets::JS("renderSparkline")) %>% 
     hot_table(highlightCol = TRUE, highlightRow = TRUE) 
     }) 

     output$second <- renderRHandsontable({ 
     dat2 %>% 
      select(a, b, c, a1, d, e, a2)%>% 
      rhandsontable(readOnly = TRUE, width = 800, 
         allowedTags = "<em><b><span><strong><a><big>") %>% 
      hot_cols(colWidths = c(50, 50, 50,80, 50, 50, 80)) %>% 
      hot_col("a", format = "0")%>% 
      hot_col("b", format = "0") %>% 
      hot_col("c", format = "0") %>% 
      hot_col("d", format = "0") %>% 
      hot_col("e", format = "0") %>% 
      hot_col("a1", renderer = htmlwidgets::JS("renderSparkline")) %>% 
      hot_col("a2", renderer = htmlwidgets::JS("renderSparkline")) %>% 
      hot_table(highlightCol = TRUE, highlightRow = TRUE) 
     }) 

    } 
    ) 
) 

이 어떤 도움 감사합니다, 감사 :

여기 내 코드입니다!

답변

1

이것은 약간의 해킹하고 더러운 해결책입니다. 그리고 나는 그것을 할 수있는 적절한 방법이 있다고 확신합니다! 그러나 span class이 두 테이블에서 같은 이름을 가리키기 때문에 (예 : span class="sparklines_r0_c3") 문제가 발생합니다. 따라서 한 가지 해결 방법은 스파크 라인을 각 테이블의 다른 열에 배치하는 것입니다. 나는 처음 dataframe에 NA 열을 추가 :

dat1$x <- NA 

후 첫 번째 테이블에 빈 1 픽셀 폭 열을 삽입 :

output$first <- renderRHandsontable({ 
dat1 %>% 
select(x, a, b, c, a1, c, d, e, a2)%>% 
rhandsontable(readOnly = TRUE, width = 801, 
       allowedTags = "<em><b><span><strong><a><big>") %>% 
hot_cols(colWidths = c(1, 50, 50, 50,80, 50, 50, 80)) %>% 
hot_col("a", format = "0")%>% 
hot_col("b", format = "0") %>% 
hot_col("c", format = "0") %>% 
hot_col("d", format = "0") %>% 
hot_col("e", format = "0") %>% 
hot_col("a1", renderer = htmlwidgets::JS("renderSparkline")) %>% 
hot_col("a2", renderer = htmlwidgets::JS("renderSparkline")) %>% 
hot_table(highlightCol = TRUE, highlightRow = TRUE) 
}) 

출력 :

enter image description here

+0

저장된 내 일. 해킹을위한 thx! – Thomas

관련 문제