본문 바로가기

개발하자

display_html 함수가 Jupyter Lab에서 작동하지 않습니다

반응형

display_html 함수가 Jupyter Lab에서 작동하지 않습니다

이 "R 코드"는 주피터에서는 잘 작동하지만 실험실에서는 잘 작동하지 않는다:

library(IRdisplay)

display_html(
'

<script>  
code_show=true; 
function code_toggle() {
  if (code_show){
    $(\'div.input\').hide();
  } else {
    $(\'div.input\').show();
  }
  code_show = !code_show
}  
$( document ).ready(code_toggle);
</script>
  <form action="javascript:code_toggle()">
    <input type="submit" value="Code On/Off">
 </form>

<style type="text/css">

.container { width:80% !important; }

.main-container {
  max-width: 2000px;
  margin-left: 100px;
  margin-right: 10px;
}

/*body{font-family: Lucida Sans Unicode} */

.nav>li>a {
    position: relative;
    display: block;
    padding: 10px 15px;
    color: #004F59;
}
.nav-pills>li.active>a, .nav-pills>li.active>a:hover, .nav-pills>li.active>a:focus {
    color: #ffffff;
    background-color: #004F59;
}

.list-group-item.active, .list-group-item.active:focus, .list-group-item.active:hover {
    background-color: #004F59;
}
</style>

'
)

나는 또한 다른 맥락에서 display_html을 사용하려고 했다. 이것이 실험실에서 작동하지 않는 이유가 있나요? 쉽게 고칠 수 있나요? 감사해요.




주피터랩에서 잘 작동하고, 당신의 기능에 대한 콜백도 잘 작동합니다. 노트북 v6와 주피터랩의 유일한 차이점은 다음과 같다:

  • jQuery는 주피터랩에서 기본적으로 사용할 수 없기 때문에(2020년대에는 더 이상 필요하지 않기 때문에), 에 의한 선택은 작동하지 않을 것이다 - 대신 표준을 사용한다
  • CSS 클래스는 서로 다르기 때문에 스타일을 조정해야 한다; 무엇을 달성하고 싶었는지 명확하지 않지만 입력 영역을 숨기는 경우 주피터랩에서 표준 JS로 동일한 효과를 얻을 수 있다:
IRdisplay::display_html('
<script type="text/javascript">
let code_show = true;
function code_toggle() {
  if (code_show) {
    document.querySelectorAll(".jp-Cell-inputArea").forEach(function(inputArea) {
      inputArea.style.display = "none";
    });
  } else {
    document.querySelectorAll(".jp-Cell-inputArea").forEach(function(inputArea) {
      inputArea.style.display = "";
    });
  }
  code_show = !code_show;
}
</script>
<form action="javascript:code_toggle()">
  <input type="submit" value="Code On/Off">
</form>
')



이것은 특정 셀이 아니라 전체 문서에 있는 모든 코드를 숨기는 것처럼 보이나요?


반응형